Solved

Find method search variable containing apostrophe

Posted on 2002-04-29
3
145 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 143

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 64
Validating VB6 Function 19 65
VBA : retain and exclude values based on a config sheet and multiple parameters 5 62
Add and format columns in vb6 7 63
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

856 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