Results 1 to 11 of 11
  1. #1
    Mrsbex's Avatar
    Mrsbex is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Devon
    Posts
    8

    Report that shows relationships in a table format

    Sorry if this has been asked before, I tried to search for "relationship report" but it told me it was too long, or too common to search for...

    Is it possible to show the relationships in a table format to print out?
    I'm looking for something like this...



    Table 1 - Table 2 - Join Properties

    eg.
    Purchase Ledger (Account Ref) - Purchase Order (Account Ref) - Indeterminate (All from both tables.)

    Is that possible?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    This works for one to many. Haven't tested for esoteric setups.
    Code:
    Public Sub GetRelationships()    
        Dim db As DAO.Database
        Dim rel As DAO.Relation
        Dim fld As DAO.Field
        Set db = CurrentDb
        For Each rel In db.Relations
            If Left(rel.Table, 4) <> "MSys" Then
                For Each fld In rel.Fields
                    Debug.Print rel.Table & " PK=" & fld.Name & " >>>>>  " & rel.ForeignTable & " FK=" & fld.ForeignName
                Next
            End If
        Next
    End Sub
    Last edited by davegri; 01-29-2019 at 08:01 AM. Reason: format

  4. #4
    Mrsbex's Avatar
    Mrsbex is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Devon
    Posts
    8
    Thanks Davegri,

    How do I incorporate that code into the database? I'm only used to using the standard interface, not modules. Sorry for my ignorance and don't worry if it's too much to explain, I can go find it on you tube if needed. I'm not expecting a tutorial lol

  5. #5
    Mrsbex's Avatar
    Mrsbex is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Devon
    Posts
    8
    Thanks orange,

    I've got this query from that link but the relationships don't give much detail...

    Code:
    SELECT MSysRelationships.szObject, MSysRelationships.szColumn, MSysRelationships.szReferencedObject, MSysRelationships.szReferencedColumn, MSysRelationships.szRelationship
    FROM MSysRelationships;
    Quote Originally Posted by orange View Post

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Relationships.zip
    To incorporate this into your DB, copy form frmOne, module basCommon, and report rptRelationships.
    All the tables in the attached db are just dummy examples to show how it looks and works.

  8. #8
    Mrsbex's Avatar
    Mrsbex is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Devon
    Posts
    8
    Thanks guys, brilliant stuff. Got what I needed, you've been a massive help!

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  10. #10
    Mrsbex's Avatar
    Mrsbex is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Devon
    Posts
    8
    Hmm, probably not on the level you guys are used to! I used the query:-

    Code:
    SELECT MSysRelationships.grbit, MSysRelationships.szObject, MSysRelationships.szColumn, MSysRelationships.szReferencedObject, MSysRelationships.szReferencedColumn, MSysRelationships.szRelationship
    FROM MSysRelationships;

    then using the link you suggested I looked at the attributes of the RelationAtributesEnum and worked out the types of relationships from the numbers under the grbit field. As I only had 5 in the end that I needed to know about I never bothered with a report and just printed out the query. Once my tables had been re-linked I re-established the relationships, and all is working well...

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 03-13-2018, 05:24 PM
  2. Replies: 2
    Last Post: 03-02-2015, 03:06 PM
  3. Custom Report That Shows Only Part Of A Table
    By phifer2088 in forum Reports
    Replies: 3
    Last Post: 08-06-2013, 11:18 AM
  4. Replies: 1
    Last Post: 07-15-2011, 10:59 PM
  5. List in Report Shows All Items in Table, But I Only Want...
    By italianfinancier in forum Programming
    Replies: 1
    Last Post: 05-28-2011, 02:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums