Create Relation : Relationship « Access « VBA / Excel / Access / Word






Create Relation

 

Sub exaRelations()
    Dim db As Database
    Dim rel As Relation
    Dim fld As Field
    
    Set db = CurrentDb
    Set rel = db.CreateRelation("PublisherRegions", "PUBLISHERS", "SALESREGIONS")
    rel.Attributes = dbRelationUpdateCascade
    Set fld = rel.CreateField("PubID")
    fld.ForeignName = "PubID"
    rel.Fields.Append fld
    db.Relations.Append rel

End Sub

 








Related examples in the same category

1.Creating a One-to-Many Relationship
2.Show all foreign tables from a relation