Help with unbound filter form code (1 Viewer)

gojets1721

Registered User.
Local time
Today, 00:12
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
 

plog

Banishment Pending
Local time
Today, 02:12
Joined
May 11, 2011
Messages
11,646
You need to replace the semicolons with apostrophes and commas. It needs to look like this:

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

gojets1721

Registered User.
Local time
Today, 00:12
Joined
Jun 11, 2019
Messages
430
That did the trick! Thanks so much!
 

Users who are viewing this thread

Top Bottom