Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: Access Other topics FAQ

Access Howto:

How to Delete All Relationships by Tzokas
Posted: 19 Jun 01

I really don't remember where in the WEB i found this article, but it is useful when you want to delete e.g. all the Tables from database but the existing relations don't allow you to go on, OR Access fails to display relations between tables in the Relationships window. Since you could not view the relationships, you could not delete them, so your database was inconsistent. This code is provided as a fix.

Function DeleteAllRelationships() As String

' WARNING: Deletes all relationships in the current database.

    Dim db As Database      ' Current DB
    Dim rex As Relations    ' Relations of currentDB.
    Dim rel As Relation     ' Relationship being deleted.
    Dim iKt As Integer      ' Count of relations deleted.
    Dim sMsg As String      ' MsgBox string.

    sMsg = "About to delete ALL relationships between tables in the current database." &     vbCrLf & "Continue?"

    If MsgBox(sMsg, vbQuestion + vbYesNo + vbDefaultButton2, "Are you sure?") = vbNo Then
        DeleteAllRelationships = "Operation cancelled"
        Exit Function

    End If
    Set db = CurrentDb
    Set rex = db.Relations
    iKt = rex.Count
    Do While rex.Count > 0
        Debug.Print rex(0).Name
        rex.Delete rex(0).Name


    DeleteAllRelationships = iKt & " relationship(s) deleted"

End Function

Hope this post was helpful

Back to Microsoft: Access Other topics FAQ Index
Back to Microsoft: Access Other topics Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close