以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]请教关于查询功能 从 组合框 换成 复选组合框后 代码该怎么改!  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=15809)

--  作者:gaoyong30000
--  发布时间:2012/1/12 13:18:00
--  [求助]请教关于查询功能 从 组合框 换成 复选组合框后 代码该怎么改!

 

组合框源代码如下:(支持模糊查询的)

Dim Filter As String
With e.Form.Controls("CheckedComboBox3")
   If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "销售顾问 Like \'*" & .Value & "*\'"
    End If
End With
With e.Form.Controls("CheckedComboBox1")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "客户来源 Like \'*" & .Value & "*\'"
    End If
End With
With e.Form.Controls("CheckedComboBox2")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "欲购车型 Like \'*" & .Value & "*\'"
    End If
End With
With e.Form.Controls("CheckedComboBox4")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "意向级别 Like \'*" & .Value & "*\'"
    End If
End With
With e.Form.Controls("DateTimePicker9")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "建档日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("DateTimePicker10")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "建档日期 <= #" & .Value & "#"
    End If
End With
Tables("销售意向客户进度管制").filter = filter

[此贴子已经被作者于2012-1-12 13:19:10编辑过]

--  作者:狐狸爸爸
--  发布时间:2012/1/12 16:11:00
--  
Dim Filter As String
With e.Form.Controls("CheckedComboBox1")
    If .Value IsNot Nothing Then
        Dim parts() As String = .Text.Split(",")
        For Each part As String In parts
            If Filter >"" Then
                Filter = Filter & " Or "
            End If
            Filter = Filter &  "销售顾问 Like \'*" & part & "*\'"
        Next
    End If
End With
messagebox.show(filter)

--  作者:gaoyong30000
--  发布时间:2012/1/12 19:22:00
--  

老大 你这个针对一个组合复选框 很不错  但是 我项目上 是多个组合复选框   复选框与复选框之间不是or  而是and             该怎么加啊?

 

 


--  作者:gaoyong30000
--  发布时间:2012/1/12 22:26:00
--  

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

--  作者:狐狸爸爸
--  发布时间:2012/1/13 8:58:00
--  

自己之间用Or,相互之间用And:

 

Dim Filter As String

With e.Form.Controls("CheckedComboBox1")
    If .Value IsNot Nothing Then
        Filter = Filter & "("
        Dim parts() As String = .Text.Split(",")
        For Each part As String In parts
            If Filter >"" Then
                Filter = Filter & " Or "
            End If
            Filter = Filter &  "销售顾问 Like \'*" & part & "*\'"
        Next
        Filter = Filter & ")"
    End If
End With
With e.Form.Controls("CheckedComboBox2")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "("
        Dim parts() As String = .Text.Split(",")
        For Each part As String In parts
            If Filter >"" Then
                Filter = Filter & " Or "
            End If
            Filter = Filter &  "客户 Like \'*" & part & "*\'"
        Next
        filter = Filter & ")"
    End If
End With
messagebox.show(filter)


--  作者:gaoyong30000
--  发布时间:2012/1/13 9:31:00
--  

老大出错!!!


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


--  作者:狐狸爸爸
--  发布时间:2012/1/13 9:34:00
--  

这种问题,应该自己可以解决:

 

MessageBox.Show(Filter)

 

 

看看生成的表达式是什么,就知道原因了:

 

 

Dim Filter As String
With e.Form.Controls("CheckedComboBox1")
    If .Value IsNot Nothing Then
        Filter = Filter & "("
        Dim parts() As String = .Text.Split(",")
        For i As Integer = 0 To parts.Length  - 1
            If i > 0  Then
                Filter = Filter & " Or "
            End If
            Filter = Filter &  "销售顾问 Like \'*" & parts(i) & "*\'"
        Next
        Filter = Filter & ")"
    End If
End With
With e.Form.Controls("CheckedComboBox2")
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "("
        Dim parts() As String = .Text.Split(",")
        For i As Integer = 0 To parts.Length  - 1
            If i > 0  Then
                Filter = Filter & " Or "
            End If
            Filter = Filter &  "客户 Like \'*" & parts(i) & "*\'"
        Next
        filter = Filter & ")"
    End If
End With
messagebox.show(filter)

[此贴子已经被作者于2012-1-13 9:36:01编辑过]

--  作者:gaoyong30000
--  发布时间:2012/1/13 13:26:00
--  
多谢 搞定了~~~~~~~
--  作者:老有所乐
--  发布时间:2012/1/13 15:10:00
--  

  请教贺老师,五楼代码中这句 “  Filter = Filter & "("   ”含义是什么

[此贴子已经被作者于2012-1-14 14:42:10编辑过]

--  作者:狐狸爸爸
--  发布时间:2012/1/13 15:18:00
--  
以下是引用老有所乐在2012-1-13 15:10:00的发言:

  请教何老师,五楼代码中这句 “  Filter = Filter & "("   ”含义是什么

 

用:

 

messagebox.show(filter)

 

就知道原因是什么了。