How to programmatically create relationship

G

Guest

In providing an automated update to a file at a remote locations, I have created new tables (CreateTableDef, etc.). Now I need to programmatically create a relationship between fields in the new table and an existing table, replete with Enforce Referential Integrity and Cascade Update.

How?
 
L

Larry Linson

In providing an automated update to a
file at a remote locations, I have created
new tables (CreateTableDef, etc.). Now
I need to programmatically create a
relationship between fields in the new
table and an existing table, replete with
Enforce Referential Integrity and
Cascade Update.

How?

Have you looked in Help at CreateRelation? Here's what Access 2002 Help has
to say about it.
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.
 
G

Guest

Thanks. That did it. I am in a little over my head, and sometimes it is hard to get to the help topic without knowing the name of the method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top