Connecting to a Microsoft Office Access Database from a VBScript

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:\ntfaq files\faq.mdb, use the following code (notice that we use the Microsoft.Jet.OLEDB.4.0 provider):

Set conn = CreateObject("ADODB.Connection")
' Connect to the database
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\NTFAQ Files\faq.mdb"
conn.Open strConnect

Once 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)
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.