Apostrophe in FindFirst

D

dhstein

We have a vendor with an apostrophe in the name like:

Joe's Widgets

When I do the command below, it fails because of that. How can I code this
to avoid the problem. Thanks for any help on this.



rsVendor.FindFirst ("VendorName = '" & VendorName & "'")
 
J

John W. Vinson

We have a vendor with an apostrophe in the name like:

Joe's Widgets

When I do the command below, it fails because of that. How can I code this
to avoid the problem. Thanks for any help on this.

Use doublequotes " to delimit the criterion rather than singlequotes '. To
put a doublequote in a doublequote delimited string use a doubled doublequote:

rsVendor.FindFirst ("VendorName = "" & VendorName & """")

That's three " characters before the first ampersand and four after.
 
C

Clif McIrvin

dhstein said:
We have a vendor with an apostrophe in the name like:

Joe's Widgets

When I do the command below, it fails because of that. How can I code
this
to avoid the problem. Thanks for any help on this.



rsVendor.FindFirst ("VendorName = '" & VendorName & "'")


Seems like I've run into that ... I've used both multiples of full
quotations - which can be tricky - and chr$(34) - which returns a full
quote.

Also, if you build your string in a variable you can use debug.print to
examine it to be certain it's properly assembled before feeding it to
the FindFirst.

So ... try:

dim strSQL as string
strSQL = "Vendor Name = " & chr$(34) & VendorName & chr$(34)
'debug.print strSQL
rsVendor.FindFirst (strSQL)

HTH!
 
D

dhstein

Thanks for your replies. I was unable to get that to work, but I found this
solution (for other people that might have this problem):

rsVendor.FindFirst ("VendorName = '" & Replace(VendorName,"'","''") & "'")

For clarity - that's " ' ", " ' ' " - replacing 1 apostrophe with 2
 

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