Help with unbound filter form code

gojets1721

Registered User.
Local time
Yesterday, 16:55
Joined
Jun 11, 2019
Messages
430
I have an unbound form to filter a report. One of the unbound fields lets the user enter a customer last name to filter down to records.

I want it so the user can enter multiple names, separated by a semi colon, and pull up records with either last name. The below code works fine if the user enters only one name, but once you enter two or more, no records show (even though there are matching records).

Code:
    With Me.txtCustomerLastName
      If Len(.Value) > 0 Then
          strCriteria = strCriteria & " AND [CustomerLastName] IN ('" & Replace(.Value, ";", ",") & "')"
      End If
    End With

If i type in Johnson;Smith into the textbox, debug.print shows this:

Code:
strCriteria: " [CustomerLastName] IN ('johnson,smith')"

Any suggestions on how to fix? I can post the full code or an example DB if needed

Thanks
 
You need to replace the semicolons with apostrophes and commas. It needs to look like this:

strCriteria: " [CustomerLastName] IN ('johnson' , 'smith')"
 
That did the trick! Thanks so much!
 

Users who are viewing this thread

Back
Top Bottom