Foxtable(狐表)用户栏目专家坐堂 → 复选框筛选


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

主题:复选框筛选

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


加好友 发短信
等级:九尾狐 帖子:2649 积分:19390 威望:0 精华:1 注册:2008/9/12 9:19:00
复选框筛选  发帖心情 Post By: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
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2011/12/4 22:52:00 [只看该作者]

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

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

 回到顶部
帅哥哟,离线,有人找我吗?
实话实说
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:九尾狐 帖子:2649 积分:19390 威望:0 精华:1 注册:2008/9/12 9:19:00
  发帖心情 Post By: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


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


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By: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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
实话实说
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:九尾狐 帖子:2649 积分:19390 威望:0 精华:1 注册:2008/9/12 9:19:00
  发帖心情 Post By: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编辑过]

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


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By: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

 


 回到顶部