Deleting table relationships with code?

  • Thread starter Thread starter Andrea
  • Start date Start date
A

Andrea

Well, I'm back here again!

I want to be able to delete certain tables with code.
When I loop through my list, I get an error that I can't
delete the table because there are existing relationships.

What is the best solution to this? Is there a way that I
can reference the relationships and delete them?

Thanks for your help! I'd be lost without you all!

Andrea
 
Hi,
Here a little sample using Relations.
It will go through them all. If you uncomment:
'dbs.Relations.Delete (dbs.Relations(i).Name)

it will also delete them all, so be careful!!

Public Sub CheckRelations()
Dim dbs As Database
Dim i As Integer

Set dbs = CurrentDb()
For i = 0 To dbs.Relations.Count - 1
With dbs.Relations(0)
Debug.Print "Properties of " & .Name & " Relation"
Debug.Print " Table = " & .Table
Debug.Print " ForeignTable = " & .ForeignTable
End With
'dbs.Relations.Delete (dbs.Relations(i).Name)
Next i

Set dbs = Nothing
End Sub
 
Back
Top