O'Reilly logo

Access™ 2007 VBA Programmer's Reference by Armen Stein, Geoffrey Griffith, Rob Cooper, Teresa Hennig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required