If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Apostrophe in FindFirst
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 & "'") |
#2
|
|||
|
|||
Apostrophe in FindFirst
On Thu, 2 Jul 2009 13:40:01 -0700, dhstein
wrote: 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. -- John W. Vinson [MVP] |
#3
|
|||
|
|||
Apostrophe in FindFirst
"dhstein" wrote in message
... 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! -- Clif |
#4
|
|||
|
|||
Apostrophe in FindFirst
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 "Clif McIrvin" wrote: "dhstein" wrote in message ... 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! -- Clif |
Thread Tools | |
Display Modes | |
|
|