以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  模糊筛选问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=177430)

--  作者:hongye
--  发布时间:2022/5/21 20:58:00
--  模糊筛选问题
Dim Filter As String
With e.Form.Controls("ComboBox8")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        If .Value.Contains("-") Then
            Dim srr() As String = .Value.split("-")
            Filter = Filter & "色号=\'" & srr(0) & "\' And 颜色=\'" & srr(1) & "\'"
        Else
            Dim txt As String = "\'%" & .Value & "%\'"
            Filter = Filter & "(色号 Like " & txt & " Or 颜色 Like " & txt & " )"
        End If
    End If
End With
With e.Form.Controls("ComboBox7")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        If .Value.Contains("-") Then
            Dim srr1() As String = .Value.split("-")
            Filter = Filter & "客户编号=\'" & srr1(0) & "\' And 面料名称=\'" & srr1(1) & "\'"
        Else
            Dim txt1 As String = "\'%" & .Value & "%\'"
            Filter = Filter & "(客户编号 Like " & txt1 & " Or 面料名称 Like " & txt1 & " )"
        End If
    End If
End With
With e.Form.Controls("ComboBox9")
    If .Text IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Dim txt2 As String = "\'%" & .Text & "%\'"
        Filter = Filter & "品牌 Like " & txt2
\'        Filter = Filter & "品牌 = \'" & .Value & "\'"
    End If 
End With
With e.Form.Controls("ComboBox10")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Dim txt3 As String = "\'%" & .Value & "%\'"
        Filter = Filter & "款号 Like " & txt3
    End If 
End With
With e.Form.Controls("ComboBox11")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Dim txt4 As String = "\'%" & .Value & "%\'"
        Filter = Filter & "交货单位 Like " & txt4
    End If 
End With
With e.Form.Controls("DateTimePicker4")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter = Filter & "交货日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("DateTimePicker5")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
        Filter = Filter & "交货日期 <= #" & .Value & "#"
    End If
End With
\'MsgBox(Filter)
Tables("窗口3_Table1").Filter = Filter

如何让代码知道ComboBox9是输入的数据还是下拉列表选择的数据呢?
我的想法是如果输入的数据模糊查找,但是下拉列表则是按照下拉列表的数据查找
比如当我ComboBox9输入1,则在表中相关列查找并筛选包含1的数据,如果ComboBox9下拉列表选择1,则是在表中相关列筛选1的数据


[此贴子已经被作者于2022/5/22 12:54:15编辑过]

--  作者:有点蓝
--  发布时间:2022/5/22 20:08:00
--  
With e.Form.Controls("ComboBox9")
    If .value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If 
if "|" & .ComboList & "|" like "*|" & .Text & "|*" then
Filter = Filter & "品牌 = \'" & .Value & "\'"
else
        Dim txt2 As String = "\'%" & .Text & "%\'"
        Filter = Filter & "品牌 Like " & txt2
endif
    End If 
End With

--  作者:hongye
--  发布时间:2022/5/22 23:19:00
--  
        If "|" & .ComboList & "|" Like "*|" & .Text & "|*" Then
            Filter = Filter & "品牌 = \'" & .Value & "\'"
        Else
            Dim txt2 As String = "\'%" & .Text & "%\'"
            Filter = Filter & "品牌 Like " & txt2
        End If

这个一旦输入的字符和ComboBox9下拉列表相同后就无法筛选了

--  作者:有点蓝
--  发布时间:2022/5/22 23:23:00
--  
首先没有办法判断是输入的数据还是下拉列表选择的数据

所以如果输入的字符和ComboBox9下拉列表相同,只能是精确查询。如果不需要这样,就没有必要区分,统一使用原来的模糊查询好了