Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
以下是筛选代码,请帮我修改一下
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
把前两段with....end with 代码放到最后面去就可以了,不过要重新定义 filter 改为 filter1 试试看。
这样也不行
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
在代码的最后加三行:
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没有任何关系了。
在代码的最后加三行:
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没有任何关系了。
我有些愚笨,麻烦帮我完善,我再学习和琢磨.
我不明白你为什么要分开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