AllExperts > Experts 
Search      

VB Script

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Igor
Expertise
WSH 5.6, ADO, CDO, WMI, IE as Object.

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

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > Vbscript - Sql - Access

Topic: VB Script



Expert: Igor
Date: 3/10/2005
Subject: Vbscript - Sql - Access

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')"  

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.