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!

Problems with an apostrophe

Status
Not open for further replies.

priapus

Technical User
May 17, 2001
26
US

I have a form that contains a combo box. the control source of this combo box is a query of companies, and when you choose one it takes you to that record for the form. yada yada, easy peasy. the problem is that one of the companies (so far) contains an apostrophe, so in the after_update code (which was simply created by the wizard) for the combo box the line:

rs.FindFirst "[companyname] = '" & Me![Combo47] & "'"

fails. What's the best way to get around this?
 
The best way I have found is to scan data on entry and replace any apostrophe ( ' ) with a ( ` ).

This problem has been aired many times on other forums and can go on for ages with people whinging about altering user entry, but for a quick fix with fairly innocuous intrusion this does it for me.
 
Only do this when you are making the data part of the SQL statement. You don't have to do it to data you are going to store.
= Replace(Me![Combo47] ,"'","''") ' Double-up apostrophe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top