以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]查询语句  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=128458)

--  作者:一只田鸡
--  发布时间:2018/12/7 14:48:00
--  [求助]查询语句
问题如下:
表里有A B C D E 五列,五列中有相同值出现的情况。
我搞了个按钮,功能为查找任意列有1这个值出现的结果。现在想要增加功能,变为查询任意列有1,并且有2出现的结果。
放两个combox 放num1 和num2的值,然后查找。
请问我的代码要怎么改?

Dim Filter As String
With e.Form.Controls("num1")
    If .Value IsNot Nothing Then
        Filter = "A = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("num1")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " Or "
        End If
        Filter = Filter & "B = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("num1")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " Or "
        End If
        Filter = Filter & "C = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("num1")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " Or "
        End If
        Filter = Filter & "D = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("num1")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " Or "
        End If
        Filter = Filter & "E = \'" & .Value & "\'"
    End If
End With
 If Filter > "" Then
     Tables("information").Filter = Filter
 End If
[此贴子已经被作者于2018/12/7 14:50:41编辑过]

--  作者:有点甜
--  发布时间:2018/12/7 16:08:00
--  

代码改成比如

 

Dim filter as string = "1=1"

Dim n1 as string = 1

If n1 <> Nothing then

    filter &= " and (a=\'" & n1 & "\' or b=\'" & n1 & "\' or c=\'" & n1 & "\')"

End If

Dim n2 as string = 2

If n2 <> Nothing then

    filter &= " and (a=\'" & n2 & "\' or b=\'" & n2 & "\' or c=\'" & n2 & "\')"

End If

msgbox(filter)