Results 1 to 9 of 9
  1. #1
    Sandro is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2018
    Posts
    4

    relations many to many for large amount of data

    Good morning and thank you in advance for your attention.


    I have to link a calendar table, made up every day of the year (in date format) to another table containing names.
    Every day of the year I must be able to link one or more names (maybe more than 100) so that by selecting a date I can see all the names present on that date, or by selecting a name I could see all the dates in which this name is present.
    Kindly I would like your help on how to structure the two tables and how to structure the relationships.
    Thank you
    Greetings

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    if this is like a classroom,
    the tStudent table would relate to the tAttend table on the StudentID field.
    1 to many. 1 student has many attend dates.

    in a single form put the tStudent record.
    in a subform it connects to the tAttend table, joined on StudentID to see all dates for the 1 student.

    or
    in a single form, unbound , put a text box (for date)
    in a subform it connects to the tAttend table, joined on DATE, to see all students for 1 date.
    (set the query of the subform to look at the date on the form)

  3. #3
    Sandro is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2018
    Posts
    4
    Thanks so much,
    I'll try.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You will need 3 tables.

    tblCalendar
    ==========
    CalendarID_PK - Autonumber
    CalendarDate - Date/Time

    (DO NOT use DATE as a field/object name - it is a reserved word and a built in function in Access)


    tblEmployees
    ============
    EmployeeID_PK - Autonumber
    EmpFirstName - Text
    EmpLastName - Text

    (DO NOT use Name as a field name - it is a reserved word in Access)


    jctEmployeesCalendar (junction table , aka many-to-many)
    ===================
    EmpCalendarID_PK - Autonumber
    EmployeeID_FK - Number Long
    CalendarID_FK- Number Long

    --------------------------------

    I would create 2 queries and 4 forms:
    Queries:
    qryEmpNames
    qryCalendarDates

    Forms:
    A main form ("frmEmpNames") with the record source of qryEmpNames
    A sub form ("sfCalendarDates") with the record source of qryCalendarDates
    Set the default view of each form to Continuous forms - Access will conplain when you add the sub form to the main form, but reset both to Continuous forms view.
    Link the main form to the sub form.

    Create another main form ("frmCalendarDates") with the record source of qryCalendarDates.
    Create another sub form ("sfEmpNames") with the record source of qryEmpNames. Set the default view of each form to Continuous forms
    Link the main form to the sub form.


    And welcome to the forum.......

  5. #5
    Sandro is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2018
    Posts
    4
    Thanks Steve, I guess this is the right direction.
    I'm having some difficulties because I've Office 2007 and something is different, and also because I'm a really a sub-first level expert.
    Thanks
    I'll let you know about it.
    Thanks again.

    Sandro

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Doesn't matter what version of Access you have. This works in Access 97, 2000, 2002, 2003, 2007, 2010, 2013, 2016, a SQLServer back end, Oracle, and dB2.
    Many to many is a database concept of how to relate two 1-to-many tables.

    If you have an A2007 dB and are having problems/, post your dB.

  7. #7
    Sandro is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2018
    Posts
    4
    Thanks Steve, it works very well. Thank you very much.
    What's the best way to prevent the possibility to insert a double identical name or data in the mask? To modify the tbl or what?
    In exemple if I use the msk frmEmpNames and I have the name "Smith" I can insert more than one record with the same date, the same for reverse with frmCalendarDates.
    Thank again
    Sandro

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In table "jctEmployeesCalendar ", create a compound INDEX.

    Open the table in design view.
    1) In the yellow "Table Tools" menu,
    2) click on Indexes. You should have one index named "PrimaryKey"
    3) Enter an index name (maybe "EmpCal"), and
    4)in the next column, select the field "EmployeeID_FK"
    5) In the next row, select "CalendarID_FK"
    6)Click back on the index name "EmpCal" and in the index properties set UNIQUE to Yes.
    Close the dialog pane.

    Click image for larger version. 

Name:	Index1.png 
Views:	7 
Size:	151.8 KB 
ID:	32737

  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,722
    Sandro,

    You may get some ideas from this free data model on StudentRoster.
    It is more complex than your set up, but the Roster table is same concept.
    There are several free generic data models at the site. They are intended as a starting point
    you can add more, remove parts etc as you wish to meet your requirements.
    Good luck.

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

Similar Threads

  1. Replies: 7
    Last Post: 06-15-2017, 10:48 AM
  2. Normalization for large amount of data
    By kvollene in forum Database Design
    Replies: 8
    Last Post: 07-01-2016, 01:18 PM
  3. Adding large amount of Excel data into Access
    By gbmarlysis in forum Access
    Replies: 4
    Last Post: 06-16-2015, 02:34 PM
  4. Replies: 12
    Last Post: 07-18-2014, 01:22 PM
  5. Replies: 13
    Last Post: 05-24-2013, 05:54 AM

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