MS-Access / Getting Started

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.

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 any of the reference methods listed, in most cases it is often more convenient to assign it to an object variable.

Dim dbs As DAO.Database
Set dbs = DBEngine(0)(0)

But far and away the most common method is to use the CurrentDb() function, described in the following section.

[Previous] [Contents] [Next]