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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

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
Robert WardlowPresidentAuthor Commented:
Thank you, worked perfectly
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
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
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Bob
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.