I need some help with my code. It's not working as intended.
Brief synopsis: I have three "filter" on my form. The user should be able to filter records by analyst name (ca_filter) and status (PSL_filter) or by project number (rec_selct).
If I take out the first IF statement, everything works fine. What I attempted to do was to add the record selection filter as a post implement "enhancement" based on user feedback. Is there a better way to accomplish the end goal?
-------------------------------------------------------
Private Sub apply_filter_Click()
Dim strWhere As String
If Me![rec_selct] > 0 Then
strWhere = "Where qry_mainform.project_id=""" & Me.rec_selct & """"
Else
If Me![CA_Filter] = " <<ALL>>" And Me![PSL_Filter] = "<<ALL>>" Then
strWhere = "Where 1=1"
Else
If Me![CA_Filter] = " <<ALL>>" And Me![PSL_Filter] <> "" Then
strWhere = "Where qry_mainform.PSL=""" & Me.PSL_Filter & """"
Else
If Me![CA_Filter] <> "" And Me![PSL_Filter] = "<<ALL>>" Then
strWhere = "Where qry_mainform.compliance_analyst=""" & Me.CA_Filter & """"
Else
If Me![CA_Filter] <> "" And Me![PSL_Filter] <> "" Then
strWhere = "Where qry_mainform.compliance_analyst=""" & Me.CA_Filter & """ AND qry_mainform.PSL=""" & Me.PSL_Filter & """"
Else
MsgBox "Search criteria can not be <NULL>", vbCritical
End If
End If
End If
End If
Thanks for the help!
Brief synopsis: I have three "filter" on my form. The user should be able to filter records by analyst name (ca_filter) and status (PSL_filter) or by project number (rec_selct).
If I take out the first IF statement, everything works fine. What I attempted to do was to add the record selection filter as a post implement "enhancement" based on user feedback. Is there a better way to accomplish the end goal?
-------------------------------------------------------
Private Sub apply_filter_Click()
Dim strWhere As String
If Me![rec_selct] > 0 Then
strWhere = "Where qry_mainform.project_id=""" & Me.rec_selct & """"
Else
If Me![CA_Filter] = " <<ALL>>" And Me![PSL_Filter] = "<<ALL>>" Then
strWhere = "Where 1=1"
Else
If Me![CA_Filter] = " <<ALL>>" And Me![PSL_Filter] <> "" Then
strWhere = "Where qry_mainform.PSL=""" & Me.PSL_Filter & """"
Else
If Me![CA_Filter] <> "" And Me![PSL_Filter] = "<<ALL>>" Then
strWhere = "Where qry_mainform.compliance_analyst=""" & Me.CA_Filter & """"
Else
If Me![CA_Filter] <> "" And Me![PSL_Filter] <> "" Then
strWhere = "Where qry_mainform.compliance_analyst=""" & Me.CA_Filter & """ AND qry_mainform.PSL=""" & Me.PSL_Filter & """"
Else
MsgBox "Search criteria can not be <NULL>", vbCritical
End If
End If
End If
End If
Thanks for the help!