VBA SQL Quote - Unquote

dh_ander

Board Regular
Joined
Jul 31, 2006
Messages
119
I am working with a linked sql table which I was able to set-up up thanks the help of you guy's here on this board.

the code below (thanx to Ahnold) is used to create the SQL statement which enables me to enter the values in my SQL table.

SQL = "INSERT INTO tblFoldersandFiles (map, datum, grootte, bestandsnaam)" & _
"VALUES ('" & strMap & "','" & strDatum & "','" & dblGrootte & _
"','" & strBestandsnaam & "')"

Basically I read a "files and folders" listing into a sql table
the problem starts when a file or folder name contains a single quote and ofcourse this can be anywhere in the string.
Any suggestions how to deal with this?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
dh_ander,
You can use the replace function to replace a value within a string. I believe the correct replacement is ' X 2 for a single '. You can replace the replace value with whatever is required though.

SQL = "INSERT INTO tblFoldersandFiles (map, datum, grootte, bestandsnaam)" & _
"VALUES ('" & Replace(strMap, "'", "''") & "','" & Replace(strDatum, "'", "''") & "','" & Replace(dblGrootte, "'", "''") & _
"','" & Replace(strBestandsnaam, "'", "''") & "')"

HTH
Cal
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top