以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]有点甜老师查询问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=129544)

--  作者:tygzjsl
--  发布时间:2018/12/31 8:19:00
--  [求助]有点甜老师查询问题

有点甜老师,我原来是按控件ComboBox建立年度项目列表,只可以查询一年的记录,比如2015年的记录,您告诉的代码如下,非常好用。

Dim Filter As String = "1=1"
With e.Form.Controls("ComboBox1")
    If .Value IsNot Nothing Then
        
        Filter = Filter & " and 年度 = \'" & .Value & "\'"
    End If
End With
Tables("信息查询表").Filter = Filter

 

 

现在我想用CheckedComboBox控件,这个控件是有复选功能,,这样就可以按照需要同时任意选择几年的记录一起看了,按原来代码这样改了一下,只能查一年,如果勾选多个确定后,就不能查询了,这种情况下代码应该是怎样,还得麻烦老师啦,谢谢!第一张截图是控件ComboBox的,只能查询一年的。第二张截图CheckedComboBox控件,想既可以查一年,也可以同时查不同年度的。

Dim Filter As String = "1=1"

With e.Form.Controls("CheckedComboBox1")
    If .Value IsNot Nothing Then
        
        Filter = Filter & " and 年度 = \'" & .Value & "\'"
    End If
End With

Tables("信息查询表").Filter = Filter
图片点击可在新窗口打开查看此主题相关图片如下:1.jpg
图片点击可在新窗口打开查看

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


--  作者:tygzjsl
--  发布时间:2018/12/31 9:31:00
--  


[此贴子已经被作者于2018/12/31 13:47:10编辑过]

--  作者:tygzjsl
--  发布时间:2018/12/31 10:50:00
--  
老师这个代码是您写的,和上面都可以达到要求,区别在哪儿啊,谢谢

With e.Form.Controls("CheckedComboBox1")

    If .Value IsNot Nothing Then

        Filter &= " and 年度 in (\'" & .Value.replace(",", "\',\'") & "\')"

    End If

End With


--  作者:tygzjsl
--  发布时间:2018/12/31 10:56:00
--  

With e.Form.Controls("checkedComboBox1")

    If .Value IsNot Nothing Then

        Filter = "nd In (\'" & .Value.Replace(",", "\',\'") & "\')"

    End If

End With

If Filter > "" Then

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

End If

老师这两个代码都能实现,有什么区别谢谢啦!

[此贴子已经被作者于2018/12/31 13:45:12编辑过]

--  作者:tygzjsl
--  发布时间:2018/12/31 13:53:00
--  
有点甜老师我建立了两checkedComboBox控件,这两个控件怎么才能达到相互筛选啊,也就是其中一个能筛选,别一个就不能筛选了,需要加什么代码,只是这样不行,需要帮助,谢谢!

With e.Form.Controls("CheckedComboBox1")

    If .Value IsNot Nothing Then

        Filter &= " and 考试时间 in (\'" & .Value.replace(",", "\',\'") & "\')"

    End If

End With


With e.Form.Controls("CheckedComboBox2")

    If .Value IsNot Nothing Then

        Filter &= " and 班级 in (\'" & .Value.replace(",", "\',\'") & "\')"

    End If

End With


--  作者:有点甜
--  发布时间:2019/1/2 10:33:00
--  
msgox(filter)弹出看看什么问题。