473,396 Members | 2,052 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,396 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 8332
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.