6.6. The Databases Collection

Using DAO, you can have more than one database open in Access at any time. If you're using an .accdb or .mdb database file, you already have one database open (called the current database). Using the Workspace object's OpenDatabase method, as shown earlier in the example in the "Using Transactions" section, you can open more than one database, and operate on them under the same workspace context. Indeed, if you were to define more than one Workspace object, you could have several databases open, each operating under a different workspace context. The Databases collection contains and manages all databases currently open in the workspace.

6.6.1. The Default (Access) Database

Unless you're working with an Access Data Project, when you create a database in Access, it is automatically added to the Databases collection.

Among its properties and methods, the Database object contains five collections: TableDefs, Containers, QueryDefs, Recordsets, and Relations. Each of these collections and their respective objects and properties are discussed in later sections. In most cases, you will be working with the default Microsoft Access database, which you can refer to using any of the following syntaxes:

DBEngine.Workspaces("#Default Workspace#").Databases(0)
DBEngine.Workspaces(0).Databases(0)
DBEngine(0).Databases(0)
DBEngine(0)(0)
CurrentDb()

The current user's default database is an object that you will use quite a lot. Although you can work with it using ...

Get Access™ 2007 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.