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?
 
Anders Ebro (Microsoft MVP)Connect With a Mentor 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
 
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
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
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.

All Courses

From novice to tech pro — start learning today.