I'm running an Insert Into SQL query from VBA, and I recently came across the string 'Women's Health / Sexual Health', which contains the ' character, and thus the query failed because ' is a text delimiter. This is how I get the text for the query:
Function getSqlInsertIntoQuery(arrHeaders, arrValues, tableIndex As enumTables)
Dim dHeadersAndValues As New scripting.Dictionary
Dim TableName As String
TableName = getTableName(tableIndex)
getSqlInsertIntoQuery = "INSERT INTO " & TableName & " ( [" & _
Join(arrHeaders, "]," & vbNewLine & "[") & "])" & _
" VALUES( " & Chr(39) & Join(arrValues, Chr(39) & "," & Chr(39)) & Chr(39) & ") ;"
Debug.Print getSqlInsertIntoQuery
End Function
Can anyone tell me of a way to clean the text of special characters that I should escape? Or is there a list of characters that I can replace using regex?