PC Review


Reply
Thread Tools Rate Thread

Adding company to an Access table

 
 
Daniel Bonallack
Guest
Posts: n/a
 
      5th May 2009
This code is actually in Excel, and I have one specific question. This is
code that enters the value myStr into an Access table called MYTABLE

For i = 1 To 5
myStr = cells(i,1).value
Sql = "INSERT INTO MYTABLE VALUES (" & Chr(39) & myStr & Chr(39) & ")"
Connection.Execute Sql
Next i

This works (it's part of a larger procedure), unless the value myStr has an
apostrophe in it - can you tell me how to upload a value with an apostrophe
in it?

thanks
Daniel Bonallack

 
Reply With Quote
 
 
 
 
joel
Guest
Posts: n/a
 
      5th May 2009
Chr(39) is an aposophe. Any apostophe in the string has to be replace wit
two aposttophes


For i = 1 To 5
myStr = cells(i,1).value
mystr = replace(mystr,chr(39),chr(39) & chr(39))
Sql = "INSERT INTO MYTABLE VALUES (" & Chr(39) & myStr & Chr(39) & ")"
Connection.Execute Sql
Next i

instead your can use
mystr = replace(mystr,"'","''")




"Daniel Bonallack" wrote:

> This code is actually in Excel, and I have one specific question. This is
> code that enters the value myStr into an Access table called MYTABLE
>
> For i = 1 To 5
> myStr = cells(i,1).value
> Sql = "INSERT INTO MYTABLE VALUES (" & Chr(39) & myStr & Chr(39) & ")"
> Connection.Execute Sql
> Next i
>
> This works (it's part of a larger procedure), unless the value myStr has an
> apostrophe in it - can you tell me how to upload a value with an apostrophe
> in it?
>
> thanks
> Daniel Bonallack
>

 
Reply With Quote
 
Daniel Bonallack
Guest
Posts: n/a
 
      5th May 2009
Thanks - that works perfectly

"joel" wrote:

> Chr(39) is an aposophe. Any apostophe in the string has to be replace wit
> two aposttophes
>
>
> For i = 1 To 5
> myStr = cells(i,1).value
> mystr = replace(mystr,chr(39),chr(39) & chr(39))
> Sql = "INSERT INTO MYTABLE VALUES (" & Chr(39) & myStr & Chr(39) & ")"
> Connection.Execute Sql
> Next i
>
> instead your can use
> mystr = replace(mystr,"'","''")
>
>
>
>
> "Daniel Bonallack" wrote:
>
> > This code is actually in Excel, and I have one specific question. This is
> > code that enters the value myStr into an Access table called MYTABLE
> >
> > For i = 1 To 5
> > myStr = cells(i,1).value
> > Sql = "INSERT INTO MYTABLE VALUES (" & Chr(39) & myStr & Chr(39) & ")"
> > Connection.Execute Sql
> > Next i
> >
> > This works (it's part of a larger procedure), unless the value myStr has an
> > apostrophe in it - can you tell me how to upload a value with an apostrophe
> > in it?
> >
> > thanks
> > Daniel Bonallack
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding company logo to business envelope under company name =?Utf-8?B?c3VlemVlODIx?= Microsoft Word Document Management 1 20th Sep 2007 10:40 PM
Adding an company long distance access code at the end of my fax =?Utf-8?B?UGFt?= Windows XP Print / Fax 1 16th Mar 2007 07:06 PM
Adding 1 row in a table in access? keri Microsoft Access 7 22nd Feb 2006 02:22 PM
Adding a key to MS Access Table =?Utf-8?B?QXJ0?= Microsoft VB .NET 6 12th Apr 2004 05:36 PM
Access to onclick events of button controls within dynamically created table + adding linked image to table cell Hrvoje Vrbanc Microsoft ASP .NET 0 11th Mar 2004 03:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 AM.