Insert string with apostrope 
Author Message
 Insert string with apostrope

Hello,
Can someone help me out with the SQL?
Can't seem to get it to work.
Thanks for any Help
Walter Levine

*************************************
Dim pAcctNo As Long
Dim sSalu As String
Dim sName As String
sSalu = "Mr."
sName = "O'Brien"
pAcctNo=100

sql = "INSERT INTO tblPatSupp " & _
             "(AcctNbr,Salutation,NameString) " & _
             "VALUES (" & _
             pAcctNo & ",'" & sSalu & "','" & sName & "')"
**********************************************



Fri, 16 Apr 2004 06:31:13 GMT  
 Insert string with apostrope
sql = "INSERT INTO tblPatSupp " & _
             "(AcctNbr,Salutation,NameString) " & _
             "VALUES (" & _
             pAcctNo & ",'" & sSalu & "','" & Replace(sName, "'", "''") &
"')"

(The 2nd argument in the Replace function is double quote-single
quote-double quote, the last argument is double quote-single quote-single
quote-double quote)

This assumes you're using VB6 or Access 2000, so that you can use the
Replace function to change the single quote to two single quotes. If you're
using a version that doesn't have the Replace function in it, check out
http://support.microsoft.com/support/kb/articles/Q188/0/07.ASP

HTH

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele


Quote:
> Hello,
> Can someone help me out with the SQL?
> Can't seem to get it to work.
> Thanks for any Help
> Walter Levine

> *************************************
> Dim pAcctNo As Long
> Dim sSalu As String
> Dim sName As String
> sSalu = "Mr."
> sName = "O'Brien"
> pAcctNo=100

> sql = "INSERT INTO tblPatSupp " & _
>              "(AcctNbr,Salutation,NameString) " & _
>              "VALUES (" & _
>              pAcctNo & ",'" & sSalu & "','" & sName & "')"
> **********************************************



Fri, 16 Apr 2004 07:35:52 GMT  
 Insert string with apostrope
HI,
Its one of the common problems most of programmers faces.
Just use
if instr(sName,"'")>0 then sName=replace(sName,"'","''")

Replace single quote with two single quotes.

Harinatha Reddy Gorla
        Software Engineer
Smart Software Technologies,
Hyderabad, India

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 16 Apr 2004 20:56:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HOW TO APPEND/INSERT STRING TO ANOTHER STRING

2. Insert string into a string

3. problem with apostrope's

4. Halndling Apostrope in SQL - Urgent

5. Inserting Symbols Into Text Strings

6. inserting a string with a single quote in between

7. inserting a string BOLD in document

8. Inserting long text string into form fields

9. How to insert RTF string into a doc ?

10. Inserting HTML string into Word document

11. Inserting a hard return into a string

12. Inserting CRLF with String.Format

 

 
Powered by phpBB® Forum Software