Connecting to a Microsoft Office Access Database from a VBScript

John Savill

April 1, 2007

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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:

Microsoft

About the Author

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.

You May Also Like