You are here:

VB Script/Vbscript - Sql - Access

Advertisement


Question
Igor,
I appreciate your help. I'm still having problems.  Here is my code again.


Set cnn=CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Online_Database\FE\Deadline DB.mdb"

sqlString = "INSERT INTO Circulation ([Circulation Day], [Circulation Week Day]) VALUES ('3/03/03', 'test'));"

cnn.execute sqlString


It says it is "missing a semi-colon at the end of the sql statement". As you can see the semi-colon is there.  I tried moving it around. adding it as & ";". Any help would again be appreciated.

Thanks,
Paul



-------------------------
Followup To
Question -
I'm trying to make a script that will add a record to a Microsoft Access 2003 database that is located on this computer.  The db is being shared out to other users through a data access page.  I got my sql to work as a manual feature (on a web page) but I need it to automatically update everyday at 6, and a vbscript will be necessary.  Here is where I am at. I have looked at a lot of examples and I am having problems with my connection string, and with opening the db and using my sql. I do not know if you need an .execute or .open command.  I appreciate any help. Please tell me if my commenting is incorrect.

'Creates an environment for the script to work
Set wshshell = WScript.CreateObject("WScript.Shell")

'Foretells of a connection to the database
Set objConnection = CreateObject("ADODB.Connection")

'Foretells of a connection to a Recordset
Set objRecordSet = CreateObject("ADODB.Recordset")

'Opens the Database
objConnection.Open "Driver={Microsoft Access Driver(*.mdb)};Dbq=C:\Online_Database\FE\Deadline DB.mdb;Uid=Admin;Pwd=;"
'objConnection.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =C:\Online_Database\FE\Deadline DB.mdb;"

'The SQL Command
objRecordSet.execute "INSERT INTO Circulation ( [Circulation Day], [Circulation Week Day] ) VALUES ('2/17/05', 'Test'));"

'Closes everything
   objRecordSet.Close
   objConnection.Close
   WScript.Quit


Answer -
for example

...
Set cnn=CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source= C:\Online_Database\FE\Deadline DB.mdb"
cnn.Execute "INSERT INTO Circulation ( [Circulation Day], [Circulation Week Day] ) VALUES ('2/17/05', 'Test'))"
...

Answer
You have superfluous ")"
...
cnn.Execute "INSERT INTO Circulation ( [Circulation Day], [Circulation Week Day] ) VALUES ('2/17/05', 'Test'!)!)"
...  


You must write so:

cnn.Execute "INSERT INTO Circulation ( [Circulation Day], [Circulation Week Day] ) VALUES ('2/17/05', 'Test')"  

VB Script

All Answers


Answers by Expert:


Ask Experts

Volunteer


Igor

Expertise

WSH 5.6, ADO, CDO, WMI, IE as Object.

Experience

WSH 5.6, ADO, CDO, WMI, IE as Object.

©2012 About.com, a part of The New York Times Company. All rights reserved.