Help with VBA filter code

tygger719

New member
Local time
Today, 14:50
Joined
Feb 24, 2005
Messages
5
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!
 
I dont see anything major wrong with your code, except your missing an "end if"

what error message are you getting when you try to run the code?
 
I get the following error message:

Run-time error '2001':

You cancelled the previous operation
 

Users who are viewing this thread

Back
Top Bottom