When you declare a database variable, you must specify the OpenDatabase() function to open the selected database. Remember that a database contains many tables. Before you can access one of the tables, you must open the database. The OpenDatabase() function informs Visual Basic that you want to access the database.
The following code declares a database variable and opens a database:
Dim dbBooks As Database Set dbBooks = OpenDatabase("Biblio.mdb")
After OpenDatabase() completes its task, Visual Basic has prepared the database and connected the database file to your Database data-typed variable. The Set command works almost like an assignment statement. Set is used to create a reference to an object. The dbBooks variable can't really hold the entire database, but dbBooks is a reference to the database.
The OpenDatabase() function generates an error if the database file doesn't exist or if a hardware error occurs when the OpenDatabase() function executes. Also, you may want to search the online help for the OpenDatabase() function options that exist for particular database types. For example, you can include a password if the database is protected, and you can open a database for exclusive access so that others on the network can't access the database until you complete your work.
The global Database data-typed variables are the few exceptions to the rule of local variable usage. The database resides outside your entire application. In every real respect, the database is global to your application due to its separation from your application. Variables, on the other hand, are internal to your program, so local variables provide safety barriers to keep some parts of the code away from some variables.
The OpenDatabase() function opens both ODBC databases and Jet engine databases. A Jet engine database is a Microsoft-designed database specification that provides quick access to databases. The database can reside in any folder and on any computer networked to yours.