Option Compare Database

Option Explicit

 

Sub AddRel_Nov_26_2007()

    ' create one-to-many relationship from PrimaryTable to ForeignTable

    Const PrimaryTable = "tlkpScholarshipStatus"

    Const PrimaryField = "Status"

    '

    Const ForeignTable = "tblSCH_Applicant"

    Const ForeignField = "Status"

    '

    Dim db As DAO.Database, rel As DAO.Relation, fld As DAO.Field

    '

    Set db = CurrentDb

    Set rel = db.CreateRelation

    With rel

        .Name = PrimaryTable & ForeignTable

        .Table = PrimaryTable

        .ForeignTable = ForeignTable

        .Fields.Append rel.CreateField(PrimaryField)

        .Fields(PrimaryField).ForeignName = ForeignField

    End With

    db.Relations.Append rel

    Set fld = Nothing

    Set rel = Nothing

    Set db = Nothing

End Sub

 

Sub DelRel_Nov26_2007()

    ' delete the relationship from PrimaryTable to ForeignTable

    Const PrimaryTable = "tlkpScholarshipStatus"

    Const ForeignTable = "tblSCH_Applicant"

    ' relation was named using concatenated table names

    Const RelationName = "tlkpScholarshipStatustblSCH_Applicant"

    '

    Dim db As DAO.Database

    '

    Set db = CurrentDb

    db.Relations.Delete RelationName

    Set db = Nothing

End Sub