473,407 Members | 2,306 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,407 software developers and data experts.

Returning Records with Apostrophes in text strings using code

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.
Nov 13 '05 #1
5 3057
"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
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.

The apostrophes don't normally cause a problem because the string is wrapped
in double quotes, eg

SELECT * FROM tblAlbum WHERE tblAlbum.TrackList LIKE "*Joe's Garage*"

Things would only go wrong when you looked for Pete "The Punk" Smith where
you would have to double up the speech marks. You could try pasting this
into a new module, which would let you simply have:

strSQL = "SELECT * FROM tblAlbum WHERE
tblAlbum.TrackList=AddQuotes(strCriterion,DoubleQu ote)

or
strCriterion = "*" & strCriterion & "*"
strSQL = "SELECT * FROM tblAlbum WHERE tblAlbum.TrackList LIKE
AddQuotes(strCriterion,DoubleQuote)

Option Compare Database
Option Explicit

Public Enum QuoteType
NoQuote
SingleQuote
DoubleQuote
End Enum
Public Function AddQuotes(strValue, Q As QuoteType) As String

Dim strReturn As String

Select Case Q

Case QuoteType.SingleQuote
strReturn = Replace(strValue, "'", "''")
strReturn = "'" & strReturn & "'"

Case QuoteType.DoubleQuote
strReturn = Replace(strValue, """", """""")
strReturn = """" & strReturn & """"

Case Else
strReturn = strValue

End Select

AddQuotes = strReturn

End Function


Nov 13 '05 #2
"Justin Hoffman" <j@b.com> wrote in message
news:d7**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
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.

The apostrophes don't normally cause a problem because the string is
wrapped in double quotes, eg

SELECT * FROM tblAlbum WHERE tblAlbum.TrackList LIKE "*Joe's Garage*"

Thanks for your response Justin. What I'm trying to return is

WHERE MyField LIKE "* ' *"

in other words any record with an apostrophe in it (so that I can remove
it). I don't seem to be able to get it to work.

Regards,
Keith.
Nov 13 '05 #3
"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
"Justin Hoffman" <j@b.com> wrote in message
news:d7**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
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.

The apostrophes don't normally cause a problem because the string is
wrapped in double quotes, eg

SELECT * FROM tblAlbum WHERE tblAlbum.TrackList LIKE "*Joe's Garage*"

Thanks for your response Justin. What I'm trying to return is

WHERE MyField LIKE "* ' *"

in other words any record with an apostrophe in it (so that I can remove
it). I don't seem to be able to get it to work.

Regards,
Keith.


Aha - just enclose it in square brackets

Like "*[']*"

or use the Instr function:

....WHERE InStr(Nz([MyField]),Chr$(39))>0
Nov 13 '05 #4
"Justin Hoffman" <j@b.com> wrote in message
news:d7**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...

Thanks for your response Justin. What I'm trying to return is

WHERE MyField LIKE "* ' *"

in other words any record with an apostrophe in it (so that I can remove
it). I don't seem to be able to get it to work.

Regards,
Keith.


Aha - just enclose it in square brackets

Like "*[']*"

or use the Instr function:

...WHERE InStr(Nz([MyField]),Chr$(39))>0

I'd already tried the square brackets but it didn't work for me (I already
use that method for finding wildcard characters) but I will have a play with
the InStr function. Many thanks again.

Keith.
Nov 13 '05 #5
"Keith" <ke*********@baeAWAYWITHITsystems.com> wrote in message
news:42**********@glkas0286.greenlnk.net...
or use the Instr function:

...WHERE InStr(Nz([MyField]),Chr$(39))>0
I'd already tried the square brackets but it didn't work for me (I already
use that method for finding wildcard characters) but I will have a play
with the InStr function. Many thanks again.


That has worked splendidly Justin, many thanks for your help.
Nov 13 '05 #6

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

Similar topics

2
by: Poster | last post by:
After creating an IN clause from a bunch of character strings created by a Word macro, Query Analyzer complains about a syntax error. The macro takes a column full of character strings and wraps...
1
by: Grant Davis | last post by:
We currently have an SQL db running on a web server. One of these fields is a large(ish) amount of text data – up to 400 characters – and has been cast variously as varchar, nchar and text type to...
3
by: James Foreman | last post by:
I've got a set of emails in a table, where sometimes they've failed to input the @ properly. Eg james.foreman'abcmail.co.uk How do I write a replace to deal with that? Also, I've got a set...
7
by: sienaman | last post by:
I have a C# dll with a COM interface that is successfully call by a C++ client. One of the parameters is a string, the method looks like void Goofy(string strUserInput, out string strOutput); ...
4
by: Nathan | last post by:
Hi, I'm doing a database app using MS Access and OleDb adapters, and I'm having trouble with getting strings containing apostrophes in and out of the database. I read through a thread below...
3
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: ...
16
by: radio1 | last post by:
---Report the current filtered records from a Form (in an ADP project)--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. ...
9
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
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: 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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.