Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to Automatically Remove Links? (A2k (9.0.3821) SR-1)

    How to Automatically Remove Links?
    A2k (9.0.3821) SR-1

    I have fe db and be db.

    Looking for some code that when run from fe db will automatically unlink/remove all attached tables in be db.

    Thanks, John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to Automatically Remove Links? (A2k (9.0.3821) SR-1)

    Here is some code using DAO:

    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef

    Set dbs = CurrentDb

    ' Loop through tabledefs.
    For Each tdf In CurrentDb.TableDefs
    ' If Connect property is not empty, table is linked.
    If Len(tdf.Connect) > 0 Then
    dbs.TableDefs.Delete tdf.Name
    End If
    Next tdf
    Set tdf = Nothing
    Set dbs = Nothing

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Automatically Remove Links? (A2k (9.0.3821) SR-1)

    Here some code to remove linked tables:
    <pre>Sub DeleteLinks()
    Dim dbs As Database
    Dim tdf As TableDef
    ' Loop through all tables in the database.
    Set dbs = CurrentDb
    For Each tdf In dbs.TableDefs
    ' If the table has a connect string, it's a linked table.
    If Len(tdf.Connect) > 0 Then
    DoCmd.DeleteObject acTable, tdf.Name
    End If
    Next tdf
    End Sub</pre>

    This will only work if the tables have no relationship. If they have, you'll have to delete them first.
    Francois

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Automatically Remove Links? (A2k (9.0.3821) SR-1)

    Once again you beat me.
    Francois

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to Automatically Remove Links? (A2k (9.0.3821) SR-1)

    Hi Francois,

    Apparently we replied at exactly the same time (13:28 our local time). It's uncanny how much our solutions resemble each other!

    Regards,
    Hans

  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Automatically Remove Links? (A2k (9.0.3821) SR-1)

    Thanks Hans & Francois

    You know the next question

    This will only work if the tables have no relationship. If they have, you'll have to delete them first.

    If Len(tdf.Connect) > 0 Then

    'Can I delete the relationship here, if so, whats the command?

    DoCmd.DeleteObject acTable, tdf.Name
    End If

    Thanks, John

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How to Automatically Remove Links? (A2k (9.0.3821) SR-1)

    The relationships with referential integrity can only be enforced on the back end. What you're removing isn't the table, it's the link.
    Charlotte

Posting Permissions

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