Access VBA syntax to to search for all records that match any of 3 fields using Like

I have a Microsoft Access 2016 continous form with 3 text fields contact1_name; contact2_name; contact_name

I would like to search for all records with a selected name that appears in any of the 3 fields using Like. Below is my working code for searching on 1 field.

Me.Filter = "[contact1_name] Like '*" & Forms![search properties broker].[namesearch] & "*' "

Below is what I think I need but my syntax is wrong and I can't  find a reference to fix it:

Me.Filter = "[contact1_name] Like '*" & Forms![search properties broker].[namesearch] & "*' " OR _
"[contact2_name] Like '*" & Forms![search properties broker].[namesearch] & "*' " OR _
"[contact3_name] Like '*" & Forms![search properties broker].[namesearch] & "*' "

I broke it onto 3 lines for clarity I am not actually looking to use it that way.

Thank you for your help.

Bob
LVL 1
Robert WardlowPresidentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
Try this:

Me.Filter = _
"[contact1_name] Like '*" & Forms![search properties broker]![namesearch] & "*' OR " & _
"[contact2_name] Like '*" & Forms![search properties broker]![namesearch] & "*' OR " & _
"[contact3_name] Like '*" & Forms![search properties broker]![namesearch] & "*'"

Open in new window

/gustav
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
hi Robert,

or you could do this:
   dim sFilter as string
   with  Forms![search properties broker] 'use Me instead if this is code behind the form
      sFilter = "[contact1_name] & [contact2_name] & [contact3_name] Like '*" & Forms![search properties broker]![namesearch] & "*'"
   end with
   me.filter = sFilter

Open in new window

if data may have ' in it, then use:
   
sFilter = "[contact1_name] & [contact2_name] & [contact3_name] Like ""*" & Forms![search properties broker]![namesearch] & "*"""

Open in new window

have an awesome day,
crystal
0
Robert WardlowPresidentAuthor Commented:
Thank you, worked perfectly
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
even though you got a solution ... I meant to change Forms![search properties broker]![namesearch] to simply ![namesearch] since it is in With
0
Robert WardlowPresidentAuthor Commented:
Thank you Crystal, even though I accepted the earlier solution, I really appreciate your input. I am going to try your suggestions too.

Many thanks.
Bob
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Bob
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.