?
Solved

Need the code to replace " with its ascii to avoid errors in a sql statement.

Posted on 2003-03-18
7
Medium Priority
?
177 Views
Last Modified: 2010-04-07
Need the code to replace " with its ascii to avoid errors in a sql statement.
0
Comment
Question by:adamkushner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:Wasim_Haider
ID: 8164044
Please, send details
0
 
LVL 3

Expert Comment

by:QJohnson
ID: 8164095
Chr$(34) is the double quote
Chr$(39) is the single

is this what you're asking for?
0
 

Author Comment

by:adamkushner
ID: 8164249
"UPDATE Invoice SET LaborDescription = (" + Chr(34) + tempText + Chr(34) + ") WHERE InvoiceNumber = invoicenumber"

invoicenumber = key
tempText = textbox contents

I need to avoid errors due to double qoutes in the text box.  How do I go about this?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
supunr earned 300 total points
ID: 8164375
Chage your Statement like below.

"UPDATE Invoice SET LaborDescription = """ & Replace(tempText, """", """ & chr(34) & """) & """ WHERE InvoiceNumber = invoicenumber"

Good Luck!
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 8164696
You don't have to change it to the ascii-code. Just replace ' by ''. This can be done by the easy statement replace

for example:
sql = "UPDATE Invoice SET LaborDescription = " & Replace(tempText, "'", "''") & "WHERE InvoiceNumber = " & invoicenumber

0
 
LVL 1

Expert Comment

by:Cliven
ID: 8165221


Chr$(34) is the double quote
Chr$(39) is the single

paste this code in vb module
Function QTrim(VVariant As Variant) As Variant
QTrim = Replace(Trim(VVariant), "'", "''")
End Function

'General sql statement using the Qtrim()
sql = "UPDATE Invoice SET LaborDescription = '" & Qtrim(Text1.text) & "' WHERE InvoiceNumber = " & invoicenumber


so every time you want to replace the ' to '' just use the qtrim(value) to do it.

easy and save time during the developing
0
 

Author Comment

by:adamkushner
ID: 8166115
This was the only answer that used double qoutes as I asked.

Cliven,
Could you show me how to use a function like that but for double qoutes? Simply replacing the single with double doesn't work.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question