VBSCRIPT/DAO-ACCESS - Esempio OLE
SCRIPT: DaoAccess.htm

<HTML>
<TITLE>Esempio DAO-ACCESS/VBScript - DAO-ACCESS</TITLE>
<BODY>
<SCRIPT LANGUAGE=VBSCRIPT>
'----------------------------------------------------------------------
' DAOACCESS.HTM - DAO Sample VBScript
' (c) 2005 Cormatron Ghost Ltd. All Rights Reserved.
'----------------------------------------------------------------------
Dim DAO_Engine ' DAO Engine object
Dim db ' DAO Database object
Dim Rs1 ' RecordSet

   ' Apertura file di Microsoft Access
   Set DAO_Engine = CreateObject("DAO.DBEngine.36") ' Set to .35 if .36 doesn't work
   Set db = DAO_Engine.Workspaces(0).OpenDatabase("c:\sample.mdb")

   ' Open the RecordSets
   Set Rs1 = db.OpenRecordSet("Studenti")

   document.writeln("<TABLE BORDER=1><TR><TH COLSPAN=4 BGCOLOR=SILVER>Tabella Studenti</TD></TR>" & _
                     "<TR><TH>Matr.</TH><TH>Cognome</TH><TH>Nome</TH><TH>Classe</TH></TR>")
   if not Rs1.Eof then
      Rs1.movefirst
      while not Rs1.eof
         document.writeln("<TR><TD>"+Cstr(Rs1("Matricola"))+"</TD>")
         document.writeln("<TD>"+Rs1("Cognome")+"</TD>")
         document.writeln("<TD>"+Rs1("Nome")+"</TD>")
         document.writeln("<TD>"+Rs1("Classe")+"</TD></TR>")
         Rs1.movenext
      wend
   end if
   document.writeln("</TABLE>")


   ' Chiusura oggetti
   Rs1.close
   db.close
   Set db = Nothing
   Set DAO_Engine = Nothing
</SCRIPT>
</BODY>
</HTML>

ESEMPIO ESECUZIONE

Lo script proposto consente di leggere il contenuto di una tabella di access all'interno di una finestra del browser IE. Il file di access utilizzato come esempio contiene una sola tabella:

Aprendo il file daoaccess.htm con Internet Explorer viene mostrato il seguente avviso di sicurezza:

Dopo aver cliccato su "Consenti contenuto bloccato ..." occorre cliccare anche sul bottone "Si" della successiva maschera di dialogo.

All'interno della finestra del browser appare lo stesso elenco visibile nella tabella Studenti presente nel file mdb di esempio.