以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  复选框筛选  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=14856)

--  作者:实话实说
--  发布时间:2011/12/4 21:03:00
--  复选框筛选


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

 

以下是筛选代码,请帮我修改一下

 

Dim Filter As String
Dim chk As WinForm.CheckBox = Forms("中兴明细").Controls("入仓")
With e.Form.Controls("入仓")
    If chk.Checked = True Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Tables("中兴明细").Filter = "[入仓数量] Is Not Null"
    End If
End With

Dim chk1 As WinForm.CheckBox = Forms("中兴明细").Controls("出仓")
With e.Form.Controls("出仓")
        If chk1.Checked = True Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Tables("中兴明细").Filter = "[出仓数量] Is Not Null"
    End If
End With

With e.Form.Controls("型号")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "型号 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("规格")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "规格 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("颜色")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "颜色 = \'" & .Value & "\'"
    End If
End With

With e.Form.Controls("开始日期")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("截止日期")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
    End If
End With
With e.Form.Controls("月份")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "月份 = \'" & .Value & "\'"
    End If
End With

If Filter > "" Then
    Tables("中兴明细").Filter = Filter
End If


 

[此贴子已经被作者于2011-12-4 22:26:27编辑过]

--  作者:mr725
--  发布时间:2011/12/4 22:52:00
--  

把前两段with....end with 代码放到最后面去就可以了,不过要重新定义 filter 改为 filter1  试试看。

[此贴子已经被作者于2011-12-4 22:52:44编辑过]

--  作者:实话实说
--  发布时间:2011/12/5 6:48:00
--  

这样也不行

Dim Filter As String
Dim Filter1 As String
Dim chk1 As WinForm.CheckBox = Forms("中兴明细").Controls("出仓")

With e.Form.Controls("型号")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "型号 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("规格")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "规格 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("颜色")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "颜色 = \'" & .Value & "\'"
    End If
End With

With e.Form.Controls("开始日期")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("截止日期")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
    End If
End With
With e.Form.Controls("月份")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "月份 = \'" & .Value & "\'"
    End If
End With

Dim chk As WinForm.CheckBox = Forms("中兴明细").Controls("入仓")
With e.Form.Controls("入仓")
    If chk.Checked = True Then
        If Filter1 >"" Then
            Filter = Filter1 & " And "
        End If
        Tables("中兴明细").Filter = "[入仓数量] Is Not Null"
    End If
End With

With e.Form.Controls("出仓")
    If chk1.Checked = True Then
        If Filter1 >"" Then
            Filter = Filter1 & " And "
        End If
        Tables("中兴明细").Filter = "[出仓数量] Is Not Null"
    End If
End With

If Filter > "" Then
    If Filter1 > "" Then
        Tables("中兴明细").Filter = Filter1
    End If
    Tables("中兴明细").Filter = Filter
End If


--  作者:狐狸爸爸
--  发布时间:2011/12/5 9:05:00
--  

在代码的最后加三行:

 

MessageBox.show("Filter1 =" & Filter1)

MessageBox.show("Filter =" & Filter)

MessageBox.show("生效的 =" & Tables("中兴明细").Filter )

 

你就知道原因了。

 

你下面的代码意义何在:

 

If Filter > "" Then
     If Filter1 > "" Then
          Tables("中兴明细").Filter = Filter1
     End If
     Tables("中兴明细").Filter = Filter
End If

 

只要Filter不为空才执行,而且Filter不为空的时候,最终将筛选条件设置成Filter了,和Filter1没有任何关系了。

[此贴子已经被作者于2011-12-5 9:04:42编辑过]

--  作者:实话实说
--  发布时间:2011/12/5 10:11:00
--  
以下是引用狐狸爸爸在2011-12-5 9:05:00的发言:

在代码的最后加三行:

 

MessageBox.show("Filter1 =" & Filter1)

MessageBox.show("Filter =" & Filter)

MessageBox.show("生效的 =" & Tables("中兴明细").Filter )

 

你就知道原因了。

 

你下面的代码意义何在:

 

If Filter > "" Then
     If Filter1 > "" Then
          Tables("中兴明细").Filter = Filter1
     End If
     Tables("中兴明细").Filter = Filter
End If

 

只要Filter不为空才执行,而且Filter不为空的时候,最终将筛选条件设置成Filter了,和Filter1没有任何关系了。

[此贴子已经被作者于2011-12-5 9:04:42编辑过]

我有些愚笨,麻烦帮我完善,我再学习和琢磨.


--  作者:狐狸爸爸
--  发布时间:2011/12/5 10:21:00
--  

我不明白你为什么要分开Filter和Filter,一个不就行啦吗:

 

 

Dim Filter As String
Dim chk1 As WinForm.CheckBox = Forms("中兴明细").Controls("入仓")
Dim chk2 As WinForm.CheckBox = Forms("中兴明细").Controls("出仓")
With e.Form.Controls("型号")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "型号 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("规格")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "规格 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("颜色")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "颜色 = \'" & .Value & "\'"
    End If
End With
With e.Form.Controls("开始日期")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 >= #" & .Value & "#"
    End If
End With
With e.Form.Controls("截止日期")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "日期 <= #" & .Value & "#"
    End If
End With
With e.Form.Controls("月份")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "月份 = \'" & .Value & "\'"
    End If
End With
If chk1.Checked = True Then
    If Filter >"" Then
        Filter = Filter & " And "
    End If
    Filter = Filter & "[入仓数量] Is Not Null"
End If
If chk2.Checked = True Then
    If Filter >"" Then
        Filter = Filter & " And "
    End If
    Filter = Filter &  "[出仓数量] Is Not Null"
End If
If Filter > "" Then
    Tables("中兴明细").Filter = Filter
End If