Relation Object (DAO)

Microsoft DAO 3.60

Relation Object

                   

A Relation object represents a relationship between fields in tables or queries (Microsoft Jet databases only).



Remarks

You can use the Relation object to create new relationships and examine existing relationships in your database.

Using a Relation object and its properties, you can:

  • Specify an enforced relationship between fields in base tables (but not a relationship that involves a query or a linked table).

  • Establish unenforced relationships between any type of table or query — native or linked.

  • Use the Name property to refer to the relationship between the fields in the referenced primary table and the referencing foreign table.

  • Use the Attributes property to determine whether the relationship between fields in the table is one-to-one or one-to-many and how to enforce referential integrity.

  • Use the Attributes property to determine whether the Microsoft Jet database engine can perform cascading update and cascading delete operations on primary and foreign tables.

  • Use the Attributes property to determine whether the relationship between fields in the table is left join or right join.

  • Use the Name property of all Field objects in the Fields collection of a Relation object to set or return the names of the fields in the primary key of the referenced table, or the ForeignName property settings of the Field objects to set or return the names of the fields in the foreign key of the referencing table.

If you make changes that violate the relationships established for the database, a trappable error occurs. If you request cascading update or cascading delete operations, the Microsoft Jet database engine also modifies the primary or foreign key tables to enforce the relationships you establish.

For example, the Northwind database contains a relationship between an Orders table and a Customers table. The CustomerID field of the Customers table is the primary key, and the CustomerID field of the Orders table is the foreign key. For Microsoft Jet to accept a new record in the Orders table, it searches the Customers table for a match on the CustomerID field of the Orders table. If Microsoft Jet doesn't find a match, it doesn't accept the new record, and a trappable error occurs.

When you enforce referential integrity, a unique index must already exist for the key field of the referenced table. The Microsoft Jet database engine automatically creates an index with the Foreign property set to act as the foreign key in the referencing table.

To create a new Relation object, use the CreateRelation method. To refer to a Relation object in a collection by its ordinal number or by its Name property setting, use any of the following syntax forms:

Relations(0)

Relations("name")

Relations![name]