View Full Version : single quote


sven2
05-07-2009, 10:21 AM
Hello,

this is something I can't get right ...
When I use a string to put a value into a table like

strSQL = " INSERT INTO ... '" & me.txtstring & "' then there is no problem exept when there is a ' sign in the string.

In access you can solve this problem like

""" & me.txtstring & """ but this doesn't work in combination with SQL ...
What is the right syntax in SQL so I can use the ' sign?

This is the string that I want to change:

strSQL = " INSERT INTO Item_Stam (Itemomschrijving, Competentie, Soortopleiding, Aspect, Geldigheidsperiode ) "
strSQL = strSQL & " VALUES ('" & [Forms]![FrmCompetentieItemToevoegen]![txtItemomschrijving] & "', "
strSQL = strSQL & "'" & [Forms]![FrmCompetentieItemToevoegen]![txtCompetentie] & "', "
strSQL = strSQL & "'" & [Forms]![FrmCompetentieItemToevoegen]![txtSoortopleiding] & "', "
strSQL = strSQL & "'" & [Forms]![FrmCompetentieItemToevoegen]![txtAspect] & "', "
strSQL = strSQL & "'" & [Forms]![FrmCompetentieItemToevoegen]![txtGeldigheidsperiode] & "' ) "
CurrentProject.Connection.Execute (strSQL)

Thanks in advance,
Sven.

MSAccessRookie
05-07-2009, 12:03 PM
chr(34) can be used to replace the ' characters in a manner similar to the following:

('" & becomes ("& chr(34) &
& "'" & becomes & chr(34) &
"') & becomes & chr(34) & " )