CreateRelation Method
Creates a new Relation object (Microsoft Jet workspaces only).
Syntax
Set relation = database.CreateRelation (name, table, foreigntable, attributes)
The CreateRelation method syntax uses these parts.
Part | Description |
---|---|
relation | An object variable that represents the Relation object you want to create. |
database | An object variable that represents the Database object for which you want to create the new Relation object. |
name | Optional. A Variant (String subtype) that uniquely names the new Relation object. See the Name property for details on valid Relation names. |
table | Optional. A Variant (String subtype) that names the primary table in the relation. If the table doesn't exist before you append the Relation object, a run-time error occurs. |
foreigntable | Optional. A Variant (String subtype) that names the foreign table in the relation. If the table doesn't exist before you append the Relation object, a run-time error occurs. |
attributes | Optional. A constant or combination of constants that contains information about the relationship type. See the Attributes property for details. |
Remarks
The Relation object provides information to the Microsoft Jet database engine about the relationship between fields in two TableDef or QueryDef objects. You can implement referential integrity by using the Attributes property.
If you omit one or more of the optional parts when you use the CreateRelation method, you can use an appropriate assignment statement to set or reset the corresponding property before you append the new object to a collection. After you append the object, you can't alter any of its property settings. See the individual property topics for more details.
Before you can use the Append method on a Relation object, you must append the appropriate Field objects to define the primary and foreign key relationship tables.
If name refers to an object that is already a member of the collection or if the Field object names provided in the subordinate Fields collection are invalid, a run-time error occurs when you use the Append method.
You can't establish or maintain a relationship between a replicated table and a local table.
To remove a Relation object from the Relations collection, use the Delete method on the collection.