以文本方式查看主题

-  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=130677)

--  作者:tygzjsl
--  发布时间:2019/1/28 20:47:00
--  [求助]有点甜老师,这两个复选怎么一起用啊!
甜老师,我建立了一个ComboBox控件,按中国的大区 ,分为东北、西北等,又建立了CheckedComboBox控件,是中国各省份的名称,怎么能达到组合筛选使用,您以前给我的代码,只能是选择了其中的一个复选框才能用。代码如下
Dim Filter As String = "1=1"
With e.Form.Controls("combobox3")
    If .Value IsNot Nothing Then
        Filter &= " and 中国地区 = \'" & .Value & "\'"
    End If
End With

With e.Form.Controls("CheckedComboBox2")
    If .Value <> Nothing Then
        Filter &= " and 省份名称 in (\'" & .Value.replace(",", "\',\'") & "\')"
    End If
End With
Tables("表A").Filter = Filter


图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20190128202948.jpg
图片点击可在新窗口打开查看

如果选了东北,下面选了东北三省,黑,吉,或辽就按东北筛选,关键是想选了东北,下面选了重庆,上海,那就按东北+重庆+上海,把符合条件的筛选出来。这样代码怎么改呢,又得麻烦你啦,谢谢!


--  作者:有点蓝
--  发布时间:2019/1/28 20:59:00
--  
东北+重庆+上海是同时符合这3个条件?还是符合其中一个即可
--  作者:tygzjsl
--  发布时间:2019/1/28 21:01:00
--  
只要符合其中一个就可以啊,谢谢!
[此贴子已经被作者于2019/1/28 21:02:36编辑过]

--  作者:有点蓝
--  发布时间:2019/1/28 21:03:00
--  
Filter &= " or 省份名称 in (\'" & .Value.replace(",", "\',\'") & "\')"
--  作者:tygzjsl
--  发布时间:2019/1/28 21:17:00
--  
蓝老师,我刚才试了,确实可以,但是我还建立了很多的复选框,如果把and改成or,那么其它的条件都乱套了,我只想让这地区和省份的能一 起组合筛选使用 ,不影响其它条件的,谢谢老师!
--  作者:有点蓝
--  发布时间:2019/1/28 21:19:00
--  
全部条件的代码都贴出来
--  作者:tygzjsl
--  发布时间:2019/1/28 21:24:00
--  
Dim Filter As String = "1=1"
With e.Form.Controls("combobox1")
    If .Value IsNot Nothing Then
        Filter = Filter & " and kl = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("combobox2")
    If .Value IsNot Nothing Then        
        Filter = Filter & " and lqpc like  \'%" & .Value &   "%\'"
    End If
End With
With e.Form.Controls("CheckedComboBox1")
    If .Value <> Nothing Then
        Filter &= " and 年度 in (\'" & .Value.replace(",", "\',\'") & "\')"
    End If
End With

With e.Form.Controls("textbox6")
    If .Value IsNot Nothing Then
        Dim str As String = ""
        For Each s As String In .value.split(" ")
            str &= "名称 like \'%" & s & "%\' or "
        Next
        Filter &= " and (" & str.substring(0, str.length-4) & ")"
    End If
End With
With e.Form.Controls("CheckedComboBox2")
    If .Value <> Nothing Then
        Filter &= " and 省份名称 in (\'" & .Value.replace(",", "\',\'") & "\')"
    End If
End With
With e.Form.Controls("combobox3")
    If .Value IsNot Nothing Then
        Filter &= " and 中国地区 = \'" & .Value & "\'"
    End If
End With

Tables("查询表").Filter = Filter


我只想让红色代码部分组合使用,不影响其它条件,谢谢!

--  作者:有点蓝
--  发布时间:2019/1/28 21:40:00
--  
单独设置条件
dim filter2 as string
With e.Form.Controls("CheckedComboBox2")
    If .Value <> Nothing Then
        filter2 = " 省份名称 in (\'" & .Value.replace(",", "\',\'") & "\')"
    End If
End With
With e.Form.Controls("combobox3")
    If .Value IsNot Nothing Then
if filter2 > "" then filter2 = filter2  & " or "
        filter2  &= " 中国地区 = \'" & .Value & "\'"
    End If
End With

if filter2 > "" then Filter Filter & " and (" & filter2  & ")"
Tables("查询表").Filter = Filter

--  作者:tygzjsl
--  发布时间:2019/1/28 21:49:00
--  
完美实现了,你太牛啦,非常感谢!