Foxtable(狐表)用户栏目专家坐堂 → 模糊筛选问题


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

主题:模糊筛选问题

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


加好友 发短信
等级:一尾狐 帖子:437 积分:2949 威望:0 精华:0 注册:2011/3/15 12:49:00
模糊筛选问题  发帖心情 Post By: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编辑过]

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


加好友 发短信
等级:超级版主 帖子:110574 积分:562760 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:2949 威望:0 精华:0 注册:2011/3/15 12:49:00
  发帖心情 Post By: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下拉列表相同后就无法筛选了

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


加好友 发短信
等级:超级版主 帖子:110574 积分:562760 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/22 23:23:00 [只看该作者]

首先没有办法判断是输入的数据还是下拉列表选择的数据

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

 回到顶部