Syntax error in query expression

G

Guest

I allow a user to insert a Client Name in one form (Entry), and when matched
in a drop-down list (Last Name), pressing a command button retrieves and
displays a pop-up form with details of that client.
The match code in the Event Procedure contains the following:

Dim stLinkCriteria As String
stLinkCriteria = "[Last Name]=" & "'" & Me![Combo64] & "'"

This works fine except when the Client name has an apostrophe (O'Doherty)
The system halts with a message:
Syntax Error (missing operator) in query expression '[Last Name]='O'Doherty.

How do I overcome this?
 
G

Guest

Try

Dim stLinkCriteria As String
stLinkCriteria = "[Last Name]=" & "'" & Replace(Me![Combo64],"'","''") & "'"
 
F

fredg

stLinkCriteria = "[Last Name]=" & "'" & Me![Combo64] & "'"

stLinkCriteria = "[Last Name]=""" & Me![Combo64] & """"

Just for clarity, that's
= " " " & Me![Combo64] & " " " "
 
G

Guest

One of almost imeediate 2 replies... both worked.
Thanks
--
GAF


fredg said:
stLinkCriteria = "[Last Name]=" & "'" & Me![Combo64] & "'"

stLinkCriteria = "[Last Name]=""" & Me![Combo64] & """"

Just for clarity, that's
= " " " & Me![Combo64] & " " " "
 
G

Guest

One of almost imeediate 2 replies... both worked.
Thanks
--
GAF


Ofer Cohen said:
Try

Dim stLinkCriteria As String
stLinkCriteria = "[Last Name]=" & "'" & Replace(Me![Combo64],"'","''") & "'"

--
Good Luck
BS"D


Gerry said:
I allow a user to insert a Client Name in one form (Entry), and when matched
in a drop-down list (Last Name), pressing a command button retrieves and
displays a pop-up form with details of that client.
The match code in the Event Procedure contains the following:

Dim stLinkCriteria As String
stLinkCriteria = "[Last Name]=" & "'" & Me![Combo64] & "'"

This works fine except when the Client name has an apostrophe (O'Doherty)
The system halts with a message:
Syntax Error (missing operator) in query expression '[Last Name]='O'Doherty.

How do I overcome this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top