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

Finding A Record In Access 1

Status
Not open for further replies.

SandraF

Programmer
Jan 25, 2001
28
US
I have the follwing code in access to find a record based on a combo box that the user picks:

strSearching = "MovieName = '" & [MovieNameComboBox] & "'"
Me.RecordsetClone.FindFirst strSearching
Me.Bookmark = Me.RecordsetClone.Bookmark

It works unless the name they are looking for has an apostrophe in it (Bram Stoker's, etc). Is there special syntax that will allow the user to search for words that might have an apostrophe in it?

Also, the above code also works if there is a hyphen or other syntax in it, just not an apostrophe.

THanks!
 
Lazy reply!!!!!

From the Help file ... Quotation Marks In Strings ...

This syntax does not permit the use of apostrophes (') within the value of the variable itself. If the value of the string variable includes an apostrophe, Microsoft Access generates a run-time error. If your variable may represent values containing apostrophes, consider using one of the other syntax forms discussed in the following sections.

Include Double Quotation Marks

You should include double quotation marks within the criteria argument in such a way so that when the value of the variable is evaluated, it will be enclosed within the quotation marks. Within a string, you must use two sets of double quotation marks to represent a single set of double quotation marks. You could construct the criteria argument as in the following example:

"[LastName] = """ & strName & """"
When the variable strName is evaluated and concatenated into the criteria argument, each set of two double quotation marks is replaced by one single quotation mark. The criteria argument becomes:

"[LastName] = 'Smith'"
This syntax may appear more complicated than the single quotation mark syntax, but it enables you to embed a string that contains an apostrophe within the criteria argument. It also enables you to nest one or more strings within the embedded string.

Hope this solves your problem.

 
LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL

(|:)>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top