Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003

    Red face Unanswered: Create Relationship with Module Code

    Hi there

    Is it possible to create and delete relationships using module code in Access 2002/XP?

    I have to regularly set up some code that will import information into a table in a database. If the table exists, I need to delete any relationships and delete the table.

    Then import the new data into a table with the same name as the deleted one and recreate the relationships

    Any thoughts how this could be done?????

    Nevermind I just worked out that it would be much easier to do with an Update Query *bangs head on desk*
    Last edited by RascalBird; 11-29-04 at 21:49. Reason: Having A Blonde Moment

  2. #2
    Join Date
    Dec 2003

    DAO Example

    Here is something I was able to find
    look at figures 5 and 6

    Dim dbsBuild As DAO.Database
    Dim relatNew
    As DAO.Relation
    Set dbsBuild =
    Set relatNew =
    dbsBuild.CreateRelation("MyRelationship", _
    "tlkp_ContactType", "contacts",

    ' Create a field in
    relation object before
    ' defining the name of
    the external field.
    = "ContactType"
    End With

    On Error Resume Next
    ' Delete the relationship if it exists.
    Set dbsBuild = CurrentDb With dbsBuild
    .Relations.Delete "MyRelationship"
    End With
    ' Delete the table in case it exists.
    DoCmd.RunSQL "Drop table tlkp_ContactType"

    On Error GoTo 0

Posting Permissions

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