Creating a Relation

Relations are created in DAO using the CreateRelation method. The syntax is:

Set RelationVar = DatabaseVar.CreateRelation _
([RelName[, KeyTable[, ForeignTable[, Attributes]]]])

where:

  • RelName is the name of the new relation.

  • KeyTable is the name of the referenced table in the relation (containing the key).

  • ForeignTable is the name of the referencing table in the relation (containing the foreign key).

  • Attributes is a constant, whose values are shown in Table 15.2.

Table 15-2. Attributes for a Relation Object

Constant

Description

dbRelationUnique

Relationship is one-to-one

dbRelationDontEnforce

No referential integrity

dbRelationInherited

Relationship exists in a noncurrent database that contains the two attached tables

dbRelationUpdateCascade

Cascading updates enabled

dbRelationDeleteCascade

Cascading deletions enabled

Notes

  • All of the properties of a Relation object become read-only after the object is appended to a Relations collection.

  • Field objects for the referenced and referencing tables must be appended to the Fields collection prior to appending the Relation object to the Relations collection.

  • Duplicate or invalid names will cause an error when the Append method is invoked.

  • To remove a Relation object from a collection, use the Delete method for that collection.

Example 15.4 illustrates the use of Relation objects. In this example, we will create a new relation in the LIBRARY database. The first step is to create a new table, using Microsoft ...

Get Access Database Design and Programming, Second Edition 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.