Microsoft Access has been the database of choice for many people for many years - and that's not really surprising because it's such an easy database to use, both for the general user and the database developer. Take, for instance, creating a database and tables from scratch - this can be done with just a few lines of VBScript code.
Creating a VBScript File
The beauty of a VBScript application is that it is simple a text file with a .vbs extension and can, therefore, be created with a text editor such as Notepad or Notepad++. Once the file has been saved then it can be run by double clicking on it.
Preparing a Computer for Use with a Database
The computer will, of course, need Microsoft Access installed and the computer will also need MDAC (Microsoft DataAccess Objects which is can be downloaded from the Microsoft Dowload Center). Once both Microsoft Access and MDAC have been installed then the computer is ready for database automation.
Creating a Microsoft Access File
The MDAC ADOX objects uses the Microsoft Jet engine to create the database file and so this and the database file name need to be saved as variables:
The MDAC's ADOX object can then be used to create the database file:
Next any required tables can be added to the database file.
Creating a Microsoft Access Database Table
MDAC's ADOX object is used to create any tables as well as the database file, and to do that a few constants are needed:
The table can now be defined:
as can any columns:
and any indexes:
and then the table can be created in the database:
Finally any memory that's been used can be freed:
With the table in place it can be populated with data.
Populating a Microsoft Access Database Table
A MDAC ADODB's connection is used to populate the table and so the next step is to create the connection:
Now the data can be inserted using a standard SQL statement:
It's worth noting that the id must be unique (so, for example, the next record should have an id of 2) and once all of the records have been loaded then again any memory that's been used can be reclaimed:
At the end of the process the table will contain a new record.
Summary
Microsoft's MDAC ADOX object is used to created the Microsoft Access database file and any tables, and then the MDAC ADODB object can be used to load any required data into the table.