Link to home
Start Free TrialLog in
Avatar of BBrian
BBrian

asked on

ADO Find Method

This does not work when the string contains a single quote.  Anyone one know a way around this?    



RstNewUserLookUp.Find ("UserID = " & "'" & strUserID & "'")
Avatar of setiawan
setiawan

Hi Bbrian,

What about using chr(39) instead of single quotes.

RstNewUserLookUp.Find "UserID = " & chr(39) & strUserID & chr(39)

from MSDN CD :
The value in criteria may be a string, floating point number, or date. String values are delimited with single quotes (for example, "state = 'WA'"). Date values are delimited with "#" (number sign) marks (for example, "start_date > #7/22/97#").

so it should be work.

  danny

ASKER CERTIFIED SOLUTION
Avatar of Marine
Marine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BBrian

ASKER

Marine
Your solution seems to work.  But I'm not sure why.  So if

UserID = "O'Malley"
then function passes
'O''Malley'

How does the search function read this expression?  
Avatar of BBrian

ASKER

setiawan
I Tried
RstNewUserLookUp.Find "UserID = " & chr(39) & strUserID & chr(39)

But it didn't work.
Has anybody else encounterd this problem
Avatar of BBrian

ASKER

Also I have found that this expression
fails if there is more than one "'"


RstNewUserLookUp.Find "USerID='" & Replace(strUserId,"'","''") & "'"
Avatar of BBrian

ASKER

Adjusted points from 50 to 100
Avatar of BBrian

ASKER

Hey Programmers!
I found an interesting article on this problem.
http://msdn.microsoft.com/library/partbook/accsybex/acsybex_chap6.htm#acsybex_topic10
Avatar of BBrian

ASKER

Thanks Marine!!
But if there is more than one "'"
it fails.  You can use "#" & struserid & "#"

But then you can't use pound signs and apostrophes together in a single
 



Your Welcome. Thanks for the points.