你好,如何将以下两段代码合在一起,这样既能够模糊查询,又能根据日期查询。谢谢。
Dim Filter As String
With e.Form.Controls("染料代号")
If .Value IsNot Nothing Then
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("StartDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "日期 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("EndDate")
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
************************************************************************
Dim filter As String
Dim sts() As String = {"染料代号","存货名称","供应商"}
For Each st As String In sts
Dim var As String = e.Form.controls(st).value
If var IsNot Nothing Then
var = var.replace("*","[*]")
If filter <> "" Then
filter = filter & " And " & st & " Like '*" & var & "*'"
Else
filter = st & " like '*" & var & "*'"
End If
End If
Next
Tables("物料信息").filter = filter