Class ModelRelationship (Excel VBA)
The class ModelRelationship represents a relationship, currently in the data model, between two tables. To use a ModelRelationship class variable it first needs to be instantiated, for example
Dim mrel as ModelRelationship
Set mrel = ActiveWorkbook.Model.ModelRelationships(Index:=1)
For Each
Here is an example of processing the ModelRelationship items in a collection.
Dim mrel As ModelRelationship
For Each mrel In ActiveWorkbook.Model.ModelRelationships
Next mrel
Active
When True, the relationship is active. When False, this relationship is inactive.
ActiveWorkbook.Model.ModelRelationships(1).Active = True
Delete
Deletes the relationship.
ActiveWorkbook.Model.ModelRelationships(1).Delete
ForeignKeyColumn
Contains the ModelTableColumn object representing the foreign key column on the many side of the one-to-many relationship.
Dim mtcForeignKeyColumn As ModelTableColumn
Set mtcForeignKeyColumn = ActiveWorkbook.Model.ModelRelationships(1).ForeignKeyColumn
ForeignKeyTable
Contains the ModelTable object representing the table on the many side of the one-to-many relationship.
Dim mdltForeignKeyTable As ModelTable
Set mdltForeignKeyTable = ActiveWorkbook.Model.ModelRelationships(1).ForeignKeyTable
PrimaryKeyColumn
Contains the ModelTableColumn object representing the primary key column in the table on the one side of the one-to-many relationship.
Dim mtcPrimaryKeyColumn As ModelTableColumn
Set mtcPrimaryKeyColumn = ActiveWorkbook.Model.ModelRelationships(1).PrimaryKeyColumn
PrimaryKeyTable
Contains the ModelTable object representing the table on the one side of the one-to-many relationship.
Dim mdltPrimaryKeyTable As ModelTable
Set mdltPrimaryKeyTable = ActiveWorkbook.Model.ModelRelationships(1).PrimaryKeyTable