VBA Access and Sql

dh_ander

Board Regular
Joined
Jul 31, 2006
Messages
119
I use the following code (just a sample) to fill a table tblFolderandFiles which is a linked table and exists in an SQL database

Code:
Dim rsFiles As ADODB.Recordset
Dim SQL As String
Dim count As Integer
Dim strMap As String
Dim strDatum As String
Dim dblGrootte As Double
Dim strBestandsnaam As String

strMap = "test2"
strDatum = "22-11-2000"
dblGrootte = 100000
strBestandsnaam = "test2.txt"

Set rsFiles = New ADODB.Recordset

With rsFiles
    .CursorType = adOpenDynamic
    .Open "select * from tblFoldersandFiles", CurrentProject.Connection
End With

rsFiles.MoveLast
DoCmd.SetWarnings (False)
For count = 1 To 10
dblGrootte = 1000 + count * 10
 SQL = "insert into tblFoldersandFiles (map,datum,grootte,bestandsnaam)" & _
  "values ('test2','10-01-2004','300','test2.txt')"
DoCmd.RunSQL SQL
Next count
DoCmd.SetWarnings (True)


rsFiles.Close

This code works and adds records to my table with " fixed" values
ofcourse I want to use variables.

if I change

Code:
('test2','10-01-2004','300','test2.txt')"
to
Code:
('strMap','strDatum',' dblGrootte','strBestandsnaam')
I get for every parameter a popup box to enter the value.
What's the correct syntax so it will use the parameter that have been defined a few lines before?
 
Vic thanks I alread learned that,

My challenge is if I have a string to determine
a) to detemine if the string contains a single quote
b) To mark the quote so it doesn't get caught.

cheers
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
David, if you need to escape a quote, just double it. So, O'Flannery becomes O''Flannery.

This is a standard SQL method.

Denis
 
Upvote 0

Forum statistics

Threads
1,225,481
Messages
6,185,249
Members
453,283
Latest member
Shortm88

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