Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Names with apostrophes 3

Status
Not open for further replies.

Hargreavesk

Technical User
Joined
Jul 18, 2001
Messages
97
Location
GB
Hi,

I'm using the following code on a search form:

Dim db As Database
Dim rs As Recordset
Set db = CurrentDb

Set rs = db.OpenRecordset("SELECT * FROM [TBL ChequeDetails] " & "WHERE Name LIKE '*" & Me!Name & "*'")

When I search for a name such as O'Brien, I get an error because of the apostrophe. Can anyone suggest some changes to my code as I'm baffled.

Regards

Kate
 
use double quotation marks to find values that contain single quotation marks and use single quotation marks in your string for values that contain quotation marks. For example,

""O'Brians""
petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
I use this for any text that could contain an apostrophe:

Set rs = db.OpenRecordset("SELECT * FROM [TBL ChequeDetails] " & "WHERE Name LIKE " & chr(34) & "*" & Me!Name & "*" & chr(34))
 
John, Peter,

Thankyou for your help. I have it working now.

Many thanks

Kate
 
i just solved this myself this morning... using the save fix as peter suggests! thanks, i just wish i saw this sooner :-)

--Junior JHauge@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top