Solved

Find method search variable containing apostrophe

Posted on 2002-04-29
3
142 Views
Last Modified: 2010-05-02
I an using the Find method to find a surname in an Access table. Everything is OK so long as I do not try to find a surname with an apostrophe in it e.g O'Donnell, O'Neill.

How can I get around this.

Here is an example of my code using the Find method

 rstSearch.Find "Surname = '" & sSurnameSearch & "'"
0
Comment
Question by:svetlana2k
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 6976983
Try this:
sSurnameSearch = replace(sSurnameSearch , "'", "''")
rstSearch.Find "Surname = '" & sSurnameSearch & "'"

Cheers
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6977014
what angellll is telling you is that in Access, when a string CONTAINS a ' or a ", you can tell the engine that the ' or " is a REAL character, and not t string terminator, by DOUBLING it: ' ---> ''  and "  ---> ""

heance using the Replace function (which ONLY works in Access 2000 and above, by the way -- the Replace function IS NOT part of the VBA in Access 97). In the code posted. the Replace function is being used to replace a ' with ''.

0
 

Author Comment

by:svetlana2k
ID: 6977044
Thanks angellll
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now