Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Location
    Costa Rica
    Posts
    40

    Unhappy Unanswered: Create Relations between tables into a module

    I have three tables: INFORME1, INFORME2 AND INFORME3. I need to make a relation between INFORME1 and INFORME2 based on the field OPERACION(no updates, deletes, no referencial integrity). and another relation between INFORME1 and INFORME3 base on the field OPERACION (no updates, deletes, no referencial integrity). All in Visual Basic for Microsoft Access, into a module. Can someone help me please...!!!!

  2. #2
    Join Date
    Jan 2003
    Location
    Rockville, MD
    Posts
    179
    Before this will work, you have to have a unique index set on the OPERACION field in table INFORME1.

    Code:
    Sub CreateRelationship()
       Dim fldNew As New Field
       Dim relNew As New Relation
       Set relNew = _
          CurrentDb.CreateRelation( _
             "INFORME1ToINFORME2", _
             "INFORME1", _
             "INFORME2")
       fldNew.Name = "OPERACION"
       fldNew.ForeignName = "OPERACION"
       relNew.Fields.Append fldNew
       CurrentDb.Relations.Append relNew
    End Sub
    You can pass attributes to the CreateReleation method:

    dbRelationDeleteCascade
    dbRelationDontEnforce
    dbRelationInherited
    dbRelationLeft
    dbRelationRight
    dbRelationUnique
    dbRelationUpdateCascade


    For example, if you wanted your relationship to cascade updates and cascade deletes, you would:
    Code:
    Sub CreateRelationship()
       Dim fldNew As New Field
       Dim relNew As New Relation
       Set relNew = _
          CurrentDb.CreateRelation( _
             "INFORME1ToINFORME2", _
             "INFORME1", _
             "INFORME2", _
             dbRelationDeleteCascade + dbRelationUpdateCascade)
       fldNew.Name = "OPERACION"
       fldNew.ForeignName = "OPERACION"
       relNew.Fields.Append fldNew
       CurrentDb.Relations.Append relNew
    End Sub

  3. #3
    Join Date
    May 2003
    Location
    Costa Rica
    Posts
    40

    Smile Problem Solved

    Thank you very much. JTRockville solve it. Please give the points to him/her. Perfectly solved. Thank you very, very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •