Create a relation : TableDefs « Access « VBA / Excel / Access / Word






Create a 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.Database relations
2.Reference column name from TableDefs
3.Add new property to TableDef
4.List table properties
5.Create an index
6.Create new field with validation rule