473,466 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Escaping punctuations and quotes

14 New Member
Hi I am new to VB. I have an access database that has data that uses the single quote like in (don't) or (g'night).

I have create a procedure that will do a search and replace, Which I thought should be simply search for (') and replace it with (& "'" &), but that just leads to a billion (& "'" &) of these being inserted. Okay maybe it's not that much but it is a lot.

Isn't there an easier way to get around "data" that uses characters that produce errors in "code". I saw an example in Perl on this site but I don't get it how to translate that into VB.

many thanks from the "geek in training"
Jul 31 '07 #1
12 1708
Killer42
8,435 Recognized Expert Expert
I don't quite follow. What sort of conversion would you like to do?
Jul 31 '07 #2
techbuddha
14 New Member
I don't quite follow. What sort of conversion would you like to do?
When I run the current script and one record has a field that has a single quote in it . I get an error. I am assuming the VB is expecting and matching single qoute. My question basically, I guess, is how do encapsulate the offending character OR what kind of substitution can I do for the offending character that will prevent the error.

The error occurs when I am doing an insert and the offending value looks something like this ( b'ad cha'ract'er). But usually it is just one ' .

I don't want to change the data the user is entering. I want them to enter the data the way they get it or the way the word is spelled. I just don't want words like M'duqes to give me an error cause there is no matching single quote .

so no transformation. more like hmmm...... chameleoning..... masqurading ..... character deception possibly ?? ;-)

right now my work around is to substitute ' with `. The later is whatever that thing is next to the #1 key in the upper left hand corner, but I think I am going down the wrong road when I start altering the data to fit the code instead of writing the code to fit the data. Not so???
Jul 31 '07 #3
Killer42
8,435 Recognized Expert Expert
Hm... well, I did read something recently about being able to delimit strings in SQL with # instead of '. Perhaps that would help. You'll probably find more help for this in the Access forum, I think.

Actually, there is an entry in their tips and tricks covering apostrophes. Perhaps it will help. You can find it in their T&T index, here. Just use the text-search function of your browser (or your own eyes, of course) to scan for "Quotes".
Jul 31 '07 #4
kentgorrell
11 New Member
In Jet (Access) you should be able to contain a string between double quotes - three each side. eg
strSQL = "SELECT * FROM tblNames WHERE Last_Name = """ & strName & """;"
You see when you use the three quotes you end up with one. You may like to see the result by inserting debug.print strSQL to print the string to the immediate window. it should look like
SELECT * FROM tblNames WHERE Last_Name = "O'Reilly";
Jul 31 '07 #5
Killer42
8,435 Recognized Expert Expert
In Jet (Access) you should be able to contain a string between double quotes - three each side. eg
strSQL = "SELECT * FROM tblNames WHERE Last_Name = """ & strName & """;" ...
Thanks for that. You can also get this effect by using Chr$(34) for the double-quote character.
Jul 31 '07 #6
kentgorrell
11 New Member
You are right CHR$(34) can be easier than trying to keep count of the double quotes.
Jul 31 '07 #7
Killer42
8,435 Recognized Expert Expert
You are right CHR$(34) can be easier than trying to keep count of the double quotes.
I think some versions of VB have a named constant you can use, like vbQuotes or something. Can't recall for sure, though. I know I have created one myself a few times, as it makes the code more readable.
Jul 31 '07 #8
techbuddha
14 New Member
so then the code could look like this

strSQL = "SELECT * FROM tblNames WHERE Last_Name = chr$(34) & strName & chr$(34);"
Jul 31 '07 #9
Killer42
8,435 Recognized Expert Expert
so then the code could look like this

strSQL = "SELECT * FROM tblNames WHERE Last_Name = chr$(34) & strName & chr$(34);"
Not quite. You need to put the value of each variable into the string, not the name of the variable. So your example would be more like...
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM tblNames WHERE Last_Name = " & Chr$(34) & strName & Chr$(34) & ";"
Jul 31 '07 #10
fplesco
82 New Member
Not quite. You need to put the value of each variable into the string, not the name of the variable. So your example would be more like...
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM tblNames WHERE Last_Name = " & Chr$(34) & strName & Chr$(34) & ";"
Hi there -

Maybe you can give this code a try:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM tblNames WHERE Last_Name = '" &  Replace(strName,"'","''") & "'"
  2.  
Basically, just REPLACE a single qoute by 2 single quotes. Same with saving values into the table. Just put REPLACE(<variable or text object>,"'","''")
to every text object or variable that you know, can contain a QUOTE.
Aug 2 '07 #11
techbuddha
14 New Member
thanks folks I think I am getting the hang of it ; -)
Aug 3 '07 #12
Killer42
8,435 Recognized Expert Expert
... Basically, just REPLACE a single qoute by 2 single quotes ...
Thanks for that, fplesco. In switching around between different programming languages, SQL and so on, I didn't remember that SQL could handle them as doubles like that.

Don't recall whether I mentioned it or not, but I just read recently that you can also use hashes (#) to delimit a string in SQL. That might resolve the immediate issue. Unless it's possible to have hashes in the string, of course - then you're back to square one. :)
Aug 3 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Reply Via Newsgroup Thanks | last post by:
Folks, This questions is directed towards PHP/MySQL folk and relates to escaping hooks, apostraphe's and other characters that can create a security hole when writing to databases/files. I've...
4
by: Dave Moore | last post by:
Hi All, Can anybody point me to a FAQ or similar that describes what all this stuff is about please?. I'm interfacing with a MySQL database if that's relavent. I've read a couple of books which...
5
by: bobbyballgame | last post by:
I am having a problem calling Stored Procedures: .... dim MyValue, MyOtherValue MyValue = "Bobby's value" MyOtherValue = Bobby's other value" rs.Open "exec MyStoredProc """ & MyValue &...
4
by: sankofa | last post by:
hi, i can't seem to be able to escape my single quote properly... is it even possible in javascript? this is a portion of my code.. var DLEWIS="Pastor Lewis"; .... Sermon is a yser-defined...
1
by: Ted Weatherly | last post by:
Hello, I want to dynamically create a table cell with a textfield in it. The value for the textfield can have quotes. e.g. I have this snippet of javascript code: var td =...
4
by: Stefan Richter | last post by:
How do I encode double quotes and quotes and in a string in VB.NET? It also has to be save for MS SQL Server... Stefan
5
by: Lucian Sandor | last post by:
Hello everyone, While I'm a newbie here, I a not new to google, so please don't send me back, it would be useless. First of all I have to specify I am working on a Blogger.com template, therefore...
7
by: duwayne | last post by:
I have a problem of escaping quotes in javascript. Ex: onclick='alert( "Mister O'Hara" )' onclick='alert( "Mister O\'Hara" )' both gives me an error. How would I escape this?
4
by: agarwalpiyush | last post by:
Hello, I am going nuts with trying to get the following to work: This is what I intend to do: I have a line in /etc/syslog.conf which I need to delete based on ip-address provided to me in a...
3
by: Taras_96 | last post by:
Hi everyone, I'm having a bit of trouble understanding the purpose of escaping nulls, and the use of addcslashes. Firstly, the manual states that: "Strictly speaking, MySQL requires only...
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
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.