Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with VBA sql string 1

Status
Not open for further replies.

tigersden

Technical User
Apr 16, 2003
81
0
0
GB
Hi,
I have written a function to loop through a table & concatenate all the Add_Info for a specific job & write it back to new table in 1 record.
On some the existing data I am getting errors, these seem to be caused by the use of ' in the concatenated text, also it appears that other characters may also be causing this.
Please could you look at my sql statement below as I believe I may have used the wrong " or ' in it.
strSQL = "INSERT INTO tblJobInfo (JOBL, ADD_INFO) " _
& "VALUES ( ' " & strJobNo & " ' , ' " & strInfo & " ' )"


JOBL is a unique job number which is alphanumeric & ADD_INFO is also alphanumeric.

Thanks in advance
Tim

 
When you want an apostrophe to store in the database, you need to double it.

Ex.

Insert Into tblJobInfo(JOBL, ADD_INFO) Values('abc123', 'Jack O''Neil')

So... to make your query work, you can do this....

strSQL = "INSERT INTO tblJobInfo (JOBL, ADD_INFO) " _
& "VALUES ( ' " & Replace(strJobNo, "'", "''") & " ' , ' " & Replace(strInfo, "'", "''") & " ' )"

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi George,
Thank you so much.
I have been trying all sorts of combinations out for hours & finally decided to post it on here.
Thanks once again
Tim
 
glad to help.

If you get better with google searches, this wouldn't have been a problem. For example, if you google search on "microsoft access apostrophe problem" you get about 147,000 hits.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top