问题解决了,所以我把我的例子调整了一下,因为不能重复上传。所以将调整后的代码贴出来了。代码如下,有需要者自取。如果需要调试的话将以下代码放进上面那个文件的筛选窗口里的“筛选”按钮里即可。
Dim Filter As String
With e.Form.Controls("DateTimePicker1")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期='" & .Value & "'"
End If
End With
With e.Form.Controls("ComboBox1")
If .Value IsNot Nothing Then
Filter = "地区 = '" & .Value & "'"
End If
End With
With e.Form.Controls("ComboBox2")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Dim ary() As String = .Value.split("-")
Filter = Filter & "室外温度 >= " & val(ary(0)) & " and 室外温度 <= " & val(ary(1))
End If
End With
With e.Form.Controls("ComboBox3")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Dim ary() As String = .Value.split("-")
Filter = Filter & "风力 >= " & val(ary(0)) & " and 风力 <= " & val(ary(1))
End If
End With
With e.Form.Controls("ComboBox4")
If .Value IsNot Nothing Then
Filter = "天气 = '" & .Value & "'"
End If
End With
With e.Form.Controls("ComboBox5")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Dim ary() As String = .Value.split("-")
Filter = Filter & "降雨量 >= " & val(ary(0)) & " and 降雨量 <= " & val(ary(1))
End If
End With
With e.Form.Controls("ComboBox6")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Dim ary() As String = .Value.split("-")
Filter = Filter & "PM2点5 >= " & val(ary(0)) & " And PM2点5 <= " & val(ary(1))
End If
End With
With e.Form.Controls("ComboBox7")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Dim ary() As String = .Value.split("-")
Filter = Filter & "空气湿度 >= " & val(ary(0)) & " and 空气湿度 <= " & val(ary(1))
End If
End With
With e.Form.Controls("ComboBox8")
If .Value IsNot Nothing Then
Filter = "外出建议 = '" & .Value & "'"
End If
End With
If Filter > "" Then
Tables("模拟广州天气分析").Filter = Filter
End If