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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
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
 

Forum statistics

Threads
1,141,718
Messages
5,708,072
Members
421,543
Latest member
SGM

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
Top