Solved

Find method search variable containing apostrophe

Posted on 2002-04-29
3
138 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
Comment Utility
Try this:
sSurnameSearch = replace(sSurnameSearch , "'", "''")
rstSearch.Find "Surname = '" & sSurnameSearch & "'"

Cheers
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
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
Comment Utility
Thanks angellll
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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

7 Experts available now in Live!

Get 1:1 Help Now