Results 1 to 8 of 8
  1. #1
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74

    Many-to-Many Relationship in a Report

    .Hi!



    Let me preface this by saying I'm working with SQL Server 2012, so I don't know of an easy way to share the database with the forum. I'll try to provide as much detail as possible.

    I'm trying to show all personnel related to a project. To do this I created a Many-to-Many relationship, because a project can have several people associated with it, and a single person can be associated with multiple projects.

    My tables:
    • tblProjects: ProjectID, ...
    • junctionProjectIndividuals: JunctionID, IndividualID, Category, ProjectID
    • tblIndividuals: IndividualsID, FirstName, LastName, ... (this table acts as an address book)

    I have a report that brings in all the data related to a single project. I'm trying to show a list of Project Personnel related to the project, but I'm stuck.

    Question: How do I create a sub-report of project personnel based on a Many-to-Many relationship.

  2. #2
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    What is the current SQL for your query behind the report?

  3. #3
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    The main report or the subreport?

    I tried to make a query that combined junctionProjectIndividuals with tblIndividuals so I would have the ProjectID field, but it came out to +100k records. Rather than having ~3 people associated with a project I had every record in the tblIndividuals table for each project.

  4. #4
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    When you say "subreport" what do you mean exactly?

  5. #5
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    My "Main" report would be the original report based on tblProject". A "Subreport" would be a way to get data from related tables into the "Main" report (based on the ProjectID primary key/foreign key relationship).

    I've modeled this in my data entry form (the "Main" form refers to fields in the tblProject table while data that are saved to related tables are in "SubForms"). In this case I'm editing junctionProjectIndividuals as a subform:
    Click image for larger version. 

Name:	2014-02-24_1324.png 
Views:	11 
Size:	136.6 KB 
ID:	15538
    The subform above represents the same relationship, but on a form rather than a Report. The "Contact" field here is filled out by tblIndividuals. When you make a selection it stores the IndividualID in the Junction table.

    Basically what I'm looking for is to use junctionProjectIndividals as a subreport, but instead of showing the IndividualID, I want to show the contact information from tblIndividuals.

    Not sure if that made it more or less clear.

    Basically I just want to be able to show all the Contacts from tblIndividuals for each project in my "Main" report. Since it's a many-to-many relationship I don't have a ProjectID in tblIndividuals so it's not as easy as tables with a one-to-many relationship.

  6. #6
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Ok, in your query behind the subreport, you need to join all three tables together just as they are set up in your relationships. This will make all fields available from all of the forms.

    Then you can link your Master Field of the main report and Child Field of the subreport so that the subreport shows the details of the item in the main report.

    You may want to consider using grouping to group the details of an item instead of a subreport.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Yes, maybe just use report Grouping & Sorting features, instead of a subreport. However, if you want to do statistics on the data (counts and sums) this will not work properly. Other methods would be needed, subreport being one.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    Quote Originally Posted by Xipooo View Post
    Ok, in your query behind the subreport, you need to join all three tables together just as they are set up in your relationships. This will make all fields available from all of the forms.

    Then you can link your Master Field of the main report and Child Field of the subreport so that the subreport shows the details of the item in the main report.

    You may want to consider using grouping to group the details of an item instead of a subreport.
    My Solution (thanks Xipooo):
    Create a query using all three tables. Design a report based on that query. Add report to main report, link Master/Child fields using ProjectID

    Thanks!

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

Similar Threads

  1. Relationship help
    By floyd in forum Database Design
    Replies: 9
    Last Post: 09-04-2013, 03:33 PM
  2. Many to many relationship on a report
    By Lois in forum Reports
    Replies: 7
    Last Post: 11-01-2011, 11:33 AM
  3. Replies: 1
    Last Post: 03-31-2010, 11:57 PM
  4. PLEASE HELP one to many relationship and a Report
    By ladieballer2004 in forum Reports
    Replies: 5
    Last Post: 08-28-2009, 07:59 PM
  5. Replies: 1
    Last Post: 12-29-2005, 01:15 PM

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