If single-quote and double-quote are in text

B

Bob Barnes

I can trap entry of single-quote and double-quote in entry from a Form, but
that can't be trapped if entered directly into a Table (unless Access
Security is set)...correct?? The Client doesn't want Access Security set.

Single-quote is for ft and double-quote is for inches (in).

I'm running code like..

Note..
Q = "SELECT Account, Make, Model, Sum([Total Inventory]) AS TotInv" _
& " FROM Orders WHERE Account = """ & P & """" _
& " And Make = """ & T & """ And Model = " & Chr(39) & U & Chr(39) & "" _
& " GROUP BY Account , Make, Model;"

where the Chr(39)..s above trap for a double-quote..

Someone in this Newsgroup was kind enough to display..
Public Function SafeString(ByVal Txt As String) As String
SafeString = Replace(Replace(Txt, Chr(39), Chr(39) & Chr(39)), Chr(34),
Chr(34) & Chr(34))
End Function

...but it's not trapping single-quote when I modify the code like..resulting
in an error.

W (a string)...
W = SafeString(U)
.....
Model = """ & W & """....

Ideas?

TIA - Bob
 
B

Bob Barnes

Thanks Doug..I'll read the other Tips also.

Douglas J. Steele said:
See my May, 2004 "Access Answers" column in Pinnacle Publication's "Smart
Access".

You can download the column (and sample database) for free at
http://www.accessmvp.com/DJSteele/SmartAccess.html

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Bob Barnes said:
I can trap entry of single-quote and double-quote in entry from a Form, but
that can't be trapped if entered directly into a Table (unless Access
Security is set)...correct?? The Client doesn't want Access Security set.

Single-quote is for ft and double-quote is for inches (in).

I'm running code like..

Note..
Q = "SELECT Account, Make, Model, Sum([Total Inventory]) AS TotInv" _
& " FROM Orders WHERE Account = """ & P & """" _
& " And Make = """ & T & """ And Model = " & Chr(39) & U & Chr(39) & "" _
& " GROUP BY Account , Make, Model;"

where the Chr(39)..s above trap for a double-quote..

Someone in this Newsgroup was kind enough to display..
Public Function SafeString(ByVal Txt As String) As String
SafeString = Replace(Replace(Txt, Chr(39), Chr(39) & Chr(39)), Chr(34),
Chr(34) & Chr(34))
End Function

..but it's not trapping single-quote when I modify the code
like..resulting
in an error.

W (a string)...
W = SafeString(U)
....
Model = """ & W & """....

Ideas?

TIA - Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top