Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
April 1, 2007
Q. How can I connect to a Microsoft Office Access database from a VBScript?
A. You can connect to an Access database by using the standard ADO database (ADODB) object. For example, to connect to Access file d:tfaq filesfaq.mdb, use the following code (notice that we use the Microsoft.Jet.OLEDB.4.0 provider):
Set conn = CreateObject("ADODB.Connection")' Connect to the databasestrConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:NTFAQ Filesfaq.mdb"conn.Open strConnectOnce connected, you can execute commands against the database. For example, to read the highest article number from a database named Saville_FAQ, use this code:StrSQL = "Select max(ArticleID) from Saville_FAQ"Set rs = conn.Execute(StrSQL)Do While not rs.EOF wscript.echo "The information is " & RS(0) intFAQNumber = RS(0) rs.MoveNextLoop
—John Savill
Read more about:
MicrosoftYou May Also Like