Avatar of Poop Holy
Poop Holy
 asked on

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
Microsoft Access

Avatar of undefined
Last Comment
Poop Holy

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Anders Ebro (Microsoft MVP)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rgonzo1971

Hi,

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

Open in new window

mbizup

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

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

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Anders Ebro (Microsoft MVP)

Good to hear. Don't forget to close the question :=)
Poop Holy

ASKER
thank bro