I'm writing a sub to filter the results on a form. Right now I have two filters, but would like to add more and am unsure of the best way to continue. I want to add combo boxes for 5 more filters. This is going to turn into a lot of nested if statements if I continue going like I am.
StrFilterSupervisor and StrFilterClient are strings returned from a combo box selection.
Right now I have:
Private Sub AnyFilterChange()
Dim SetFilter As String
If (StrFilterClient = "" And StrFilterSupervisor = "") Then
DoCmd.ShowAllRecords
Else
If StrFilterClient = "" Then
SetFilter = StrFilterSupervisor
Else
If StrFilterSupervisor = "" Then
SetFilter = StrFilterClient
Else
SetFilter = StrFilterClient & " AND " & StrFilterSupervisor
End If
End If
DoCmd.ApplyFilter , SetFilter
End If
End Sub
StrFilterSupervisor and StrFilterClient are strings returned from a combo box selection.
Right now I have:
Private Sub AnyFilterChange()
Dim SetFilter As String
If (StrFilterClient = "" And StrFilterSupervisor = "") Then
DoCmd.ShowAllRecords
Else
If StrFilterClient = "" Then
SetFilter = StrFilterSupervisor
Else
If StrFilterSupervisor = "" Then
SetFilter = StrFilterClient
Else
SetFilter = StrFilterClient & " AND " & StrFilterSupervisor
End If
End If
DoCmd.ApplyFilter , SetFilter
End If
End Sub