I have set up a form to filter my report with. I want to be able to filter my name field using a text box and typing in a comma separated string that would use the "contains" wildcard for each item in the string. Is it possible to filter by multiple "contains" using a text box? If so, please help me with the code. Here is what I have so far for code.
Private Sub cmdApplyFilter_Click()
Dim strName As String
Dim strProjectUseFunction As String
Dim strFilter As String
Dim strYearCompleted As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Barb's report") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build Name criteria string
If IsNull(Me.txtName.Value) Then
strName = "Like '*'"
Else
strName = "Like '*" & Me.txtName.Value & "*'"
' Build Use / Function criteria string
If IsNull(Me.txtProjectUseFunction.Value) Then
strProjectUseFunction = "Like '*'"
Else
strProjectUseFunction = "Like '*" & Me.txtProjectUseFunction.Value & "*'"
End If
' Build Year Completed >
If IsNull(Me.txtYearCompleted.Value) Then
strYearCompleted = "Like '*'"
Else
strYearCompleted = "> '" & Me.txtYearCompleted.Value & "'"
End If
' Build filter string
strFilter = "[Name] " & strName & _
" AND [Project Use / Function] " & strProjectUseFunction & _
" AND [Year Completed] " & strYearCompleted
' Apply filter to report
With Reports![Barb's report]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub cmdRemoveFilter_Click()
On Error Resume Next
Reports![Barb's report].FilterOn = False
End Sub
Private Sub cmdApplyFilter_Click()
Dim strName As String
Dim strProjectUseFunction As String
Dim strFilter As String
Dim strYearCompleted As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acReport, "Barb's report") <> acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build Name criteria string
If IsNull(Me.txtName.Value) Then
strName = "Like '*'"
Else
strName = "Like '*" & Me.txtName.Value & "*'"
' Build Use / Function criteria string
If IsNull(Me.txtProjectUseFunction.Value) Then
strProjectUseFunction = "Like '*'"
Else
strProjectUseFunction = "Like '*" & Me.txtProjectUseFunction.Value & "*'"
End If
' Build Year Completed >
If IsNull(Me.txtYearCompleted.Value) Then
strYearCompleted = "Like '*'"
Else
strYearCompleted = "> '" & Me.txtYearCompleted.Value & "'"
End If
' Build filter string
strFilter = "[Name] " & strName & _
" AND [Project Use / Function] " & strProjectUseFunction & _
" AND [Year Completed] " & strYearCompleted
' Apply filter to report
With Reports![Barb's report]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Private Sub cmdRemoveFilter_Click()
On Error Resume Next
Reports![Barb's report].FilterOn = False
End Sub