Foxtable(狐表)用户栏目专家坐堂 → [求助]查询语句


  共有1107人关注过本帖树形打印复制链接

主题:[求助]查询语句

帅哥哟,离线,有人找我吗?
一只田鸡
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:33 积分:379 威望:0 精华:0 注册:2018/8/28 16:39:00
[求助]查询语句  发帖心情 Post By: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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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)


 回到顶部