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.

Syntax

Description

Example

Collection("name")

Literal string

DBEngine(0

).Databases

"myDB")

Collection(position)

Ordinal collection position

DBEngine(0

).Databases

0)

Collection(variable)

String or variant variable

strVar = "

myDB"

DBEngine(0

).Databases

strVar)

Collection![Name]

Object name

DBEngine(0

).Databases

myDB

Where the object name contains nonstandard characters, such as spaces, you must enclose the object name in square brackets [ ].

Finally, throughout this chapter, I have used the convention of capitalizing the first character of object and collection names, to highlight the difference between them and the casual use of the same word for other purposes. The following example illustrates this convention:

The Database object is an instance of a connection to a database or other data source. It is a member of the Workspace object's Databases collection, which is a container for a group of Database objects that represent connections to one or more databases.

0 0

Post a comment