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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search variable with ' character

Status
Not open for further replies.

codo

IS-IT--Management
Oct 31, 2001
187
ID
I want to search a record where the value containing ' character, but it result an error. Here's the example

FindText = "Joy's car"
With rs_temp
.MoveFirst
.Find "item = '" & UCase(FindText) & "'"
end with

but if i change the FindText = "Joys car" the code running with no errors.

How can i search record that contain ' character ?
 
Double up on the single quote (use two single quotes -NOT a double quote):

"Joy''s car"
or
"Joy" & chr$(39) & chr$(39) & "s car"

You can achieve this simply by using the VBA Replace() function.
 
Use the replace function on your variable
i.e.

Code:
FindText = "Joy's car"
findtext = replace(FindText,"'", "''")

granted this could be done in one line but I broke it into two lines to demonstrate the replace function.



Andy Baldwin

"Testing is the most overlooked programming language on the books!"

Ask a great question, get a great answer. Ask a vague question, get a vague answer.
Find out how to get great answers FAQ219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top