以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 列表查询 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=30512) |
-- 作者:jpguo -- 发布时间:2013/3/29 13:05:00 -- 列表查询 以下是列表中【查询】按钮的代码: Dim Filter As String With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "LCMC like \'*" & .Value & "*\'" End If End With With e.Form.Controls("DateTimePicker1") If .Value IsNot Nothing Then If Filter >"" Then Filter = Filter & " And " End If Filter = Filter & "RQ >= #" & .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 & "RQ <= #" & .Value & "#" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then Filter = "KHBM like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "KHMC like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "LXR like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "LXDH like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "SHDZ like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "SSXQ like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "XSQD like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "KHDJ like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "BBBM like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "BBYWY like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "BBDGY like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "GZZT like \'*" & .Value & "*\'" End If End With With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "BZ like \'*" & .Value & "*\'" End If End With If Filter > "" Then Tables("YXKH").Filter = Filter End If ------------------------------------------------------------------------- 问题:我把其他字段的的条件注释掉,单独只留LCMC(如下),执行查询是正常的,但是像上面那样,全部执行的时候,LCMC这个字段的条件就失效,求解! Dim Filter As String
With e.Form.Controls("模糊条件") If .Value IsNot Nothing Then If Filter > "" Then Filter = Filter & " OR " End If Filter = Filter & "LCMC like \'*" & .Value & "*\'" End If End With If Filter > "" Then Tables("YXKH").Filter = Filter End If |
-- 作者:狐狸爸爸 -- 发布时间:2013/3/29 14:27:00 -- 你的条件中,有的用and连接起来,有的用Or连接起来。
A and B and c
只有b或c中有一个不成立,A不管是否成立,表达式都是false
A or B or c
只有b或c中有一个成立,A不管是否成立,表达式都是True
什么是有用and,什么时候用or,你自己首先要理清楚,还要注意用括号对条件分组。
|