HowTo Connect HTML with MS Access

This example script shows you how to get started in web/database development by connecting an HTML page to an MS Access database via VbScript.


   Dim objConn
   Dim objRec
   Dim strConnect
   Dim Query

   ' Put an SQL query into a string
   Query = "select * from orders;"

   ' Access file must reside locally. A URL won't work
   strConnect = "C:/My Documents/NorthWind.mdb"

   ' We access the database thru an ADO connection
   Set objConn = CreateObject ("ADODB.connection")

   ' This tells which provider / driver to use

   ' Opens the database connection
   objConn.Open strConnect

   ' Creates a recordset to hold the data coming back from the query
   Set objRec = CreateObject ("ADODB.Recordset")

   ' Causes the query to execute
   objRec.Open Query, objConn

   ' Output each record
   do while not objRec.EOF
      document.write (objRec.Fields(0).Value)
      document.write (" --->> ")
      document.write (objRec.Fields(1).Value)
      document.write ("<br />")

   ' Close the recordset
   set objRec = nothing

   ' Close the database connection
   set objConn = nothing


Leave a Reply