A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Apostrophe in FindFirst



 
 
Thread Tools Display Modes
  #1  
Old July 2nd, 2009, 09:40 PM posted to microsoft.public.access
dhstein
external usenet poster
 
Posts: 665
Default 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  
Old July 2nd, 2009, 10:55 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default 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  
Old July 2nd, 2009, 10:59 PM posted to microsoft.public.access
Clif McIrvin[_2_]
external usenet poster
 
Posts: 629
Default 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  
Old July 5th, 2009, 04:53 PM posted to microsoft.public.access
dhstein
external usenet poster
 
Posts: 665
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:30 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.