具体的逻辑只有你清楚,最重要的是将执行筛选这部分提出来,放在最后,其他自己调整:
Dim Filter As String
With e.Form.Controls("jieshou")
If .Value IsNot Nothing Then
Filter = "jieshoudanwei = '" & .Value & "'"
End If
End With
With e.Form.Controls("laiyuan")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "laiyuanjing = '" & .Value & "'"
End If
End With
With e.Form.Controls("danju")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "danjuzhuangtai = '" & .Value & "'"
End If
End With
With e.Form.Controls("weixiu")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "weixiuzhuangtai = '" & .Value & "'"
End If
End With
With e.Form.Controls("chanpin")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "chanpin_xinghao = '" & .Value & "'"
End If
End With
With e.Form.Controls("jihao")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "jihao = '" & .Value & "'"
End If
End With
If e.Form.Controls("sxriqi").Checked = True
With e.Form.Controls("kai")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "sx_riqi >= #" & .Value & "#"
End If
End With
End If
With e.Form.Controls("jieshu")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "sx_riqi <= #" & .Value & "#"
End If
End With
If e.Form.Controls("jieriqi").Checked = True
With e.Form.Controls("kai")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "jieshouriqi >= #" & .Value & "#"
End If
End With
End If
With e.Form.Controls("jieshu")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "jieshouriqi <= #" & .Value & "#"
End If
End With
If e.Form.Controls("pairiqi").Checked = True
With e.Form.Controls("kai")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "pai_riqi >= #" & .Value & "#"
End If
End With
End If
With e.Form.Controls("jieshu")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "pai_riqi <= #" & .Value & "#"
End If
End With
If e.Form.Controls("huiriqi").Checked = True
With e.Form.Controls("kai")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "weixiuriqi >= #" & .Value & "#"
End If
End With
End If
With e.Form.Controls("jieshu")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "weixiuriqi <= #" & .Value & "#"
End If
End With
If Filter > "" Then
Tables("信息追踪_table1").Filter = Filter
End If
[此贴子已经被作者于2014-2-27 14:48:58编辑过]