I'm trying to execute an SQL statement in a loop that contains some strings which have single quotes ( ' ) in the text of the string. I've set the SQL statement itself as a string so then I can replace double quotes with 2 double quotes and tried to do the same for single quotes but it still throws an error.
SQLString = "INSERT INTO dbo.CSF_Reports (CorpName, ReportType, ReportDate, FileNumber, OldCode) VALUES ('" & (rsOldSource.Fields.Item("
Corporatio
n_Name").V
alue) & "','" & (rsOldSource.Fields.Item("
Report_Typ
e_ID").Val
ue) & "','" & (rsOldSource.Fields.Item("
Report_Dat
e").Value)
& "','" & (rsOldSource.Fields.Item("
File_Numbe
r").Value)
& "'," & (rsOldSource.Fields.Item("
Report_ID"
).Value) & ")"
SQLString = replace(SQLString, """", """""")
SQLString = replace(SQLString, "''", "''''")
The error occurs when it gets to a record with Corporation_Name of something liKe: Bob's Furniture
Start Free Trial