6.4. Referring to DAO Objects

In code, you refer to objects in the DAO hierarchy by working your way down the object hierarchy. The following format illustrates generally how to reference DAO objects:

DBEngine.ParentCollection.ChildCollection!Object.Method_or_Property

You might recall from earlier discussion that a collection is a container for a group of objects of the same type. Many DAO object collections contain still other collections, so it is sometimes necessary to drill down through several collections before you get to the object that you want to operate on. This provides a highly structured and predictable method for accessing data and schema.

With the exception of the DBEngine object, all DAO objects are contained within their own collections. For example, the TableDef object is part of a TableDefs collection, and the Group object is part of a Groups collection. As a way of distinguishing between collections and individual objects, those that are named in the plural (ending with the letter s) are collections, whereas those named in the singular are individual objects.

Collections provide an easy way to enumerate their members by allowing you to refer to them by their name or ordinal position. You can also populate a variable with the object's name and use it instead. For example, the following examples show how you can refer to the same object in different ways.

SyntaxDescriptionExample
Collection("name")Literal stringDBEngine.Workspaces(0).Databases("myDB")
Collection(position) ...

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.