以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  按日期段筛选有点儿问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=141926)

--  作者:cyrollin
--  发布时间:2019/10/14 15:14:00
--  按日期段筛选有点儿问题
Dim Filter As String
Dim txt As String = e.Form.Controls("ComboBox1").Text
With e.Form.Controls("ComboBox1")
    If .Value IsNot Nothing Then
        txt = "\'%" & txt & "%\'"
        filter = "姓名 Like " & txt & " Or 客户信息 Like " & txt 
        vars("姓名") = txt
    End If
End With

With e.Form.Controls("DateTimePicker1")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
        vars("起始日期") = .Value
    End If
End With

With e.Form.Controls("DateTimePicker2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
        vars("终止日期") = .Value
    End If
End With

If Filter > "" Then
    DataTables("表A").loadfilter = filter
    DataTables("表A").load()
    Tables("表A").Filter = Filter
end If

筛选出来日期段不是 datatimepicker1和datatimepicker2控件选出来的日期段。

--  作者:有点蓝
--  发布时间:2019/10/14 15:18:00
--  
代码没有问题,上传实例说明
--  作者:cyrollin
--  发布时间:2019/10/14 15:50:00
--  
Dim Filter As String
Dim txt As String = e.Form.Controls("ComboBox1").Text
With e.Form.Controls("ComboBox1")
    If .Value IsNot Nothing Then
        txt = "\'%" & txt & "%\'"
        filter = "姓名 Like " & txt & " Or 客户信息 Like " & txt  (‘ 问题是出现在紫色代码这一段,如果去掉就正常了。但我也想查询姓名字段和客户信息字段这二栏)
        vars("姓名") = txt
    End If
End With

With e.Form.Controls("DateTimePicker1")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
        vars("起始日期") = .Value
    End If
End With

With e.Form.Controls("DateTimePicker2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
        vars("终止日期") = .Value
    End If
End With

If Filter > "" Then
    DataTables("表A").loadfilter = filter
    DataTables("表A").load()
    Tables("表A").Filter = Filter
end If

筛选出来日期段不是 datatimepicker1和datatimepicker2控件选出来的日期段。

--  作者:有点蓝
--  发布时间:2019/10/14 15:55:00
--  
With e.Form.Controls("ComboBox1")
    If .Value IsNot Nothing Then
        txt = "\'%" & txt & "%\'"
        filter = "(姓名 Like " & txt & " Or 客户信息 Like " & txt & ")"
        vars("姓名") = txt
    End If
End With

--  作者:cyrollin
--  发布时间:2019/10/14 17:33:00
--  
可以了,谢谢