473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using words with apostrophes in filter

Hi,

I have a form with an unbound textbox for entering a name to search for with

strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for
a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing
with the aphostrophe used in my strSQL. But how to I overcome this problem?

Thanx
Alex
Nov 12 '05 #1
3 8327
One way I sometimes address this is to "escape" the apostrophe, like this:
Replace(Me.SurnameSearch,"'","''")
Here it is with added spaces for clarity: (Don't use it in this form,
though.)
Replace(Me.SurnameSearch," ' "," ' ' ")

HTH
- Turtle

"Alex Ng" <au**********@hotmail.com> wrote in message
news:bk**********@lust.ihug.co.nz...
Hi,

I have a form with an unbound textbox for entering a name to search for with
strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing with the aphostrophe used in my strSQL. But how to I overcome this problem?
Thanx
Alex

Nov 12 '05 #2
"Alex Ng" <au**********@hotmail.com> wrote in message news:<bk**********@lust.ihug.co.nz>...
Hi,

I have a form with an unbound textbox for entering a name to search for with

strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for
a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing
with the aphostrophe used in my strSQL. But how to I overcome this problem?

Thanx
Alex


Instead os using apostrophes uses double quotes eg
strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = """ &
Me.SurnameSearch & """"
Nov 12 '05 #3
For any special characters in a string I use the chr$(x) function
where the value of x could say 34 for double quotes, 39 for single
quotes etc.

To find what should be the value of a specific special character I use
the following simple method in Excel.

1) Open a blank worksheet
2) Enter 0 in A1
3) In A2 enter the formula "=A1+1" (only what is between the double
quotes).
4) Copy the formula from A2 down the column A upto A256
5) In B1 enter the formula "=CHAR(A1)" (only what is between the
double quotes).
6) Copy the formula in B1 down the column B upto B256.

Manually search for the special character down Column B and use the
corresponding value in Column A as your value of x.

Executing the 6 steps above takes less than a minute.

So in the example below, instead of the single quotes, use Chr$(39).

Hope this helps.

Cheers!

Uttam
================

Hope this helps.

al********@hotmail.com (Alex) wrote in message news:<49**************************@posting.google. com>...
"Alex Ng" <au**********@hotmail.com> wrote in message news:<bk**********@lust.ihug.co.nz>...
Hi,

I have a form with an unbound textbox for entering a name to search for with

strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for
a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing
with the aphostrophe used in my strSQL. But how to I overcome this problem?

Thanx
Alex


Instead os using apostrophes uses double quotes eg
strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = """ &
Me.SurnameSearch & """"

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Brynn | last post by:
I want to thank the person that sent the nasty messages to my contact.asp test page ... you have inspired me !!! I have now added a bad_words filter both to my JSValidation script (going up on...
11
by: Sandfordc | last post by:
I have tried several time to do this but have been unsucessful. I tried something like: myFunction(charater) str=frm.s1.value sb1=str.substring(0,charater)...
3
by: Richard Hollenbeck | last post by:
I have an email field and a command button to send email. The problem is that when the email program opens up there are apostrophes around the email address that I have to manually remove before...
5
by: Keith | last post by:
I've tried various combinations of quotation marks and asterisks but I can't see to get the syntax right. Could someone post a working example? Many thanks. Keith.
4
by: Thomas | last post by:
I want to be able to implement a filter that manipulates the output from the server... Maybe replacing some words, or highlighting a search string, or some other fancy feature... I want to make...
2
by: engwar1 | last post by:
I'm building a page for a website that will allow for anonymous users to post comments. I want to filter out words deemed offensive or obscene. I know HOW to build this feature but I'm wondering if...
2
by: ChianHsieh | last post by:
Hi, I face some problem that I want to filter the all words in HTML. Example: Before Filter: <div id="pp"hello man <br/Thank's for your answer. </div> After Filter:
3
by: Tracey | last post by:
Is there a way to include the quote mark/character when using the MessageBox.Show? In other words is there an alternative/secondary delimiter for strings in VB2005? <"denotes the desired...
0
by: mark r | last post by:
Hi there... im on with my shoutbox again only now i want to add a bad words filter. ive got the following code off a website and would appreciate someone showing me how to integrate it into my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.