Default Collection Items

Let's say you wanted to retrieve the DefaultValue property for a field called PaymentDate in a table called tblPayments. This is the long way of doing it:

DBEngine![#Default

Workspace#].Databases(0).TableDefs!tblPayments.Fields!PaymentDate.DefaultValue

As you can see, referring to objects, properties, and methods can sometimes result in quite long lines of code. This can get pretty tedious after a while, so you can also refer to objects by their parent collection's default item. Assuming tblPayments is the first table in the TableDefs collection, and PaymentDate is the first field in that table's Fields collection, here is the shortened version:

DBEngine(0)(0)(0)(0).DefaultValue

The default item for any DAO object collection is the item that occupies ordinal position 0. This is in contrast to VBA collections, in which the first member occupies position 1—an important fact to remember.

The following table lists examples of the two ways you can use to refer to DAO collection members.

Collection

Default Member

Example

Containers

Documents

DBEngine.Workspaces(0).Databases

.Containers(0).Docu^ents(0)

DBEngine(0)(0).Containers(0)(0)

0)

Databases

TableDefs

DBEngine.Workspaces(0).Databases .TableDefs(0) DBEngine(0)(0)(0)

0)

DBEngines

Workspaces

DBEngine.Workspaces(0) DBEngine(0)

Groups

Users

DBEngine.Workspaces(0).Groups(0) DBEngine(0).Groups(0)(0)

Users(0)

QueryDefs

Parameters

DBEngine.Workspaces(0).Databases

.QueryDefs(0).Parameters(0)

DBEngine(0)(0).QueryDefs(0)(0)

0)

Recordsets

Fields

DBEngine.Workspaces(0).Databases

.Recordsets(0).Fields(0)

DBEngine(0)(0).Recordsets(0)(0)

0)

Continues

Collection

Default Member

Example

Relations

Fields

DBEngine.Workspaces(0).Databases(0)

.Relations(0).Fields(0)

DBEngine(0)(0).Relations(0)(0)

TableDefs

Fields

DBEngine.Workspaces(0) .TableDefs(0).Fields(0 DBEngine(0)(0)(0)(0)

.Databases(0) )

Users

DBEngine(0).Groups(0)(

.Groups(0) 0)(0)

Workspaces

Databases

DBEngine.Workspaces(0) DBEngine(0)

0 0

Post a comment