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
Solved

MS Access List All Tables that Do Not Have Relationships

Posted on 2015-01-12
7
92 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
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

839 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