Run Time Error'3075': Syntax Error(Missing Operator) in query expression 'Name = Lee'

Run Time Error'3075': Syntax Error(Missing Operator) in query expression 'Name = Lee'

my codes : DoCmd.OpenForm "Medical Record" , , , "Name = " & Me.txtName
Poop HolyAsked:
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.

Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Strings need to be enclosed in quotes.
DoCmd.OpenForm "Medical Record" , , , "Name = '" & Me.txtName & "'"

Open in new window


I added a single quote do the where clause, before and after the me.txtName
0

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
Rgonzo1971Commented:
Hi,

pls try
my codes : DoCmd.OpenForm "Medical Record" , , , "Name = '" & Me.txtName & "'"

Open in new window

0
mbizupCommented:
The error is due to the fact that text needs to be delimited with quotes.  Your original code, which does not use delimiters would work with a Numeric field.

For text, you need to enclose the name in quotes.  As in previous comments, this will work in most cases:

DoCmd.OpenForm "Medical Record" , , , "[Name] = '" & Me.txtName & "'"

Open in new window


However, this method will error with Irish patients like O'Hara and O'Malley.  

For NAME data,  the following method is preferable to avoid errors caused by apostrophes:

DoCmd.OpenForm "Medical Record" , , , "[Name] = " & chr(34) & Me.txtName & chr(34) 

Open in new window


Also, "Name" might need square brackets, as it is a special word in Access.
1
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.

Poop HolyAuthor Commented:
yea, thx , I solved by adding quotes at the back
DoCmd.OpenForm "Medical Record" , , , "[Name] = '" & Me.txtName & "'"

Open in new window

0
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Good to hear. Don't forget to close the question :=)
0
Poop HolyAuthor Commented:
thank bro
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.