Solved

MS Access List All Tables that Do Not Have Relationships

Posted on 2015-01-12
7
97 Views
Last Modified: 2015-03-22
Hi,
Is there a way to list all tables in an MS Access database that do not have relationships ?
Your assistance is greatly appreciated.
Kind Regards,
Mohamed
0
Comment
Question by:Mohamed Singh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 40545274
Are you trying to identify the explicit relationships (defined in the UI) or the implicit relationships (established in queries)?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40545288
For explicit relationships, use this:
Option Explicit


Sub Q_28595093()
    Dim rel As Relation
    Dim dbRels As Relations
    Dim dicUnique As Object
    Dim tbl As TableDef
    
    Set dicUnique = CreateObject("scripting.dictionary")
    Set dbRels = DBEngine(0)(0).Relations
    For Each rel In dbRels
        If dicUnique.Exists(rel.Table) Then
            dicUnique.Exists(rel.Table) = dicUnique.Exists(rel.Table) + 1
        Else
            dicUnique.Add rel.Table, 1
        End If
        If dicUnique.Exists(rel.ForeignTable) Then
            dicUnique.Exists(rel.ForeignTable) = dicUnique.Exists(rel.ForeignTable) + 1
        Else
            dicUnique.Add rel.ForeignTable, 1
        End If
    Next
    For Each tbl In DBEngine(0)(0).TableDefs
        If dicUnique.Exists(tbl.Name) Then
        Else
            Debug.Print tbl.Name, "has no defined relation"
        End If
    Next
End Sub

Open in new window

0
 

Author Comment

by:Mohamed Singh
ID: 40553839
Hi aikimark,

Thank You responding.
My apologies for my delayed response.

I'm trying to identify tables which do not have explicit relationships.

I tried running your code but get error:

Run-time error '451':
Property let procedure not defined and property get procedure did not return an object

on line 19

Kind Regards,
Mohamed
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 45

Expert Comment

by:aikimark
ID: 40554019
Oops.  Please test this version:
Option Explicit


Sub Q_28595093()
    Dim rel As Relation
    Dim dbRels As Relations
    Dim dicUnique As Object
    Dim tbl As TableDef
    
    Set dicUnique = CreateObject("scripting.dictionary")
    Set dbRels = DBEngine(0)(0).Relations
    For Each rel In dbRels
        If dicUnique.Exists(rel.Table) Then
            dicUnique.Exists(rel.Table) = dicUnique.Exists(rel.Table) + 1
        Else
            dicUnique.Add rel.Table, 1
        End If
        If dicUnique.Exists(rel.ForeignTable) Then
            dicUnique.Exists(rel.ForeignTable) = dicUnique(rel.ForeignTable) + 1
        Else
            dicUnique.Add rel.ForeignTable, 1
        End If
    Next
    For Each tbl In DBEngine(0)(0).TableDefs
        If dicUnique.Exists(tbl.Name) Then
        Else
            Debug.Print tbl.Name, "has no defined relation"
        End If
    Next
End Sub

Open in new window

0
 

Author Comment

by:Mohamed Singh
ID: 40568449
Hi aikimark,
Again, my apologies for the very late response - the new year has loads of things to get done!
Thank You for this second post.
Regrettably,the same error now occurs on line 14.
Kind Regards,
Mohamed
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 40568659
One more try:
Option Explicit


Sub Q_28595093()
    Dim rel As Relation
    Dim dbRels As Relations
    Dim dicUnique As Object
    Dim tbl As TableDef
    
    Set dicUnique = CreateObject("scripting.dictionary")
    Set dbRels = DBEngine(0)(0).Relations
    For Each rel In dbRels
        If dicUnique.Exists(rel.Table) Then
            dicUnique(rel.Table) = dicUnique(rel.Table) + 1
        Else
            dicUnique.Add rel.Table, 1
        End If
        If dicUnique.Exists(rel.ForeignTable) Then
            dicUnique(rel.ForeignTable) = dicUnique(rel.ForeignTable) + 1
        Else
            dicUnique.Add rel.ForeignTable, 1
        End If
    Next
    For Each tbl In DBEngine(0)(0).TableDefs
        If dicUnique.Exists(tbl.Name) Then
        Else
            Debug.Print tbl.Name, "has no defined relation"
        End If
    Next
End Sub

Open in new window

0
 

Author Closing Comment

by:Mohamed Singh
ID: 40681226
Hi aikimark,

Many Thanks - No errors.
Please excuse the very very delayed response.

Kindest Regards,
Mohamed
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question