Context: Windows7, VBScript, ADODB and ADOX.
I have written some VBScript code which creates a database, creates three tables, loads one of them with data and then attempts to issue a set of SQL statements against these tables.
Everything works fine except that last step: The SQL statements, when taken into Access’s own query builder, work fine. They don’t appear to work outside Access and there are no error messages. The SQL statements are echoed and apparently executed but the access database contents don’t change. I’m at a loss to figure out why.
Const dbFile = "C:\database.mdb"
strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Mode=Read|Write;Data Source=" & dbFile
...
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adDouble = 5
Const adInteger = 3
Const adCmdText = 1
Const adLockOptimistic = 3
Const adOpenDynamic = 2
Const adCmdTable = &H0002
Const adUseClient = 3
...
Set objConn = CreateObject("ADODB.Connection")
objConn.CursorLocation = adUseClient
objConn.Open strDSN
Set objCmd = CreateObject("ADODB.Command")
Set o = createobject("Std.Ini2")
o.Load "C:\Queries.ini"
d = o.GetValue("Setup", "Queries", vbNullString)
a = Split( d, ", ")
For Each s In a
cmd = o.GetValue(s,"Query",vbNullString)
WScript.Echo cmd
With objCmd
Set .ActiveConnection = objConn
.CommandText = cmd
.CommandType = adCmdText
.CommandTimeout = 60
.Prepared = True
.Execute
End With
Next
Std.Ini2 is one of my own tools and talks to the INI file.
An example slice out of the INI follows:
[Qry-01b-Delete Products from Extg product-import]
Query=DELETE [Product-import].* FROM [Product-import];
[Qry-02-Append Feed To Product-import]
Query=INSERT INTO [Product-import] ( product_sku, product_name, product_price ) SELECT Feed.Col1, Feed.Col2, Feed.Col3 FROM Feed;
[Qry-03a-Delete All Records From Exisiting Category Path Builder]
Query=DELETE [Tbl_Category Path builder].* FROM [Tbl_Category Path builder];
[Qry-03b-Append Products to Category Builder]
Query=INSERT INTO [Tbl_Category Path builder] ( SKU, Product ) SELECT Feed.Col1, Feed.Col2 FROM Feed;
The three tables, as you may have worked out, are called “Feed”, “Product-import” and “Tbl_Category Path builder”.
Solution (for me at least) was to stop using ADODB.Command and use the Execute method of ADODB.Connection instead, viz