Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共6 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:复选框筛选

1楼
实话实说 发表于: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编辑过]
2楼
mr725 发表于:2011/12/4 22:52:00

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

[此贴子已经被作者于2011-12-4 22:52:44编辑过]
3楼
实话实说 发表于: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楼
狐狸爸爸 发表于: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楼
实话实说 发表于: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楼
狐狸爸爸 发表于: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

 

共6 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02734 s, 2 queries.