Findfirst / criteria with a string that has apostrophe (')

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I was struggling with that until I saw this posting.
I used to replace any apostrophe with a question mark (wildcard for a single
character), then use "Like" in my criteria, for example: "[Lastname] Like '"
& replace(myString,"'","?") & chr(39).
But it's not 100% safe.
Thanks to this posting, I searched the section "Quotation Marks in Strings"
in the Access VBA help and got a detailed explanation of Tim's and Gunny's
useful answer.
Thanks
 
hi Christian,
I used to replace any apostrophe with a question mark (wildcard for a single
character), then use "Like" in my criteria, for example: "[Lastname] Like '"
& replace(myString,"'","?") & chr(39).
But it's not 100% safe.
Sorry, but it's nonsens.

You have to escape (double) the quotes you are using while building the
criteria string:

"[Lastname] Like '" & Replace(myString, "'", "''") & "'"


mfG
--> stefan <--
 

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

Back
Top