Hello,
I have a subform with a query recordsource that I am now trying to allow the user to select multiple choices from combo boxes. Currently, it filters on only one combo box and disables all other choices.
My combo boxes are State, Activity, Status, Planner, Building and Requestor.
How would I change this code (copied from Capricorn1's solution to the related question) to filter based on one or all combo box selections?
Sub ApplyFilter()
Dim sFilter As String
sFilter = ""
If Me.txtState <> "" And Not IsNull(Me.txtState) Then
If sFilter = "" Then
sFilter = "[State] Like '*" & Me!txtState & "*'"
Else
sFilter = sFilter & " and [State] Like '*" & Me!txtState & "*'"
End If
End If
If Me.txtCounty <> "" And Not IsNull(Me.txtCounty) Then
If sFilter = "" Then
sFilter = "[County] Like '*" & Me!txtCounty & "*'"
Else
sFilter = sFilter & " And [County] Like '*" & Me!txtCounty & "*'"
End If
End If
If Me.txtCity <> "" And Not IsNull(Me.txtCity) Then
If sFilter = "" Then
sFilter = "[City] Like '*" & Me!txtCity & "*'"
Else
sFilter = sFilter & " And [City] Like '*" & Me!txtCity & "*'"
End If
End If
If Me.txtZip <> "" And Not IsNull(Me.txtZip) Then
If sFilter = "" Then
sFilter = "[Zip] Like '*" & Me!txtZip & "*'"
Else
sFilter = sFilter & " And [Zip] Like '*" & Me!txtZip & "*'"
End If
End If
If Len(sFilter) > 0 Then
Me!SubSearchUSA.Form.Filte
r = sFilter
Me!SubSearchUSA.Form.Filte
rOn = True
Else
Me!SubSearchUSA.Form.Filte
r = ""
Me!SubSearchUSA.Form.Filte
rOn = False
End If
End Sub
Private Sub txtstatel_AfterUpdate()
ApplyFilter
End Sub
Private Sub txtcounty_AfterUpdate()
ApplyFilter
End Sub
Private Sub txtcity_AfterUpdate()
ApplyFilter
End Sub
Private Sub txtzip_AfterUpdate()
ApplyFilter
End Sub
Thanks
Start Free Trial