Sub forms to link data (1 Viewer)

SwampyNZ

New member
Local time
Today, 21:14
Joined
Jan 9, 2024
Messages
11
Hello

I am writing an access database to link appointing officials to tournaments.

I have a table called Tournaments (contains an auto-number for Tournament_ID and a number field for Contact_ID), and a table called contacts (contains an autonumber for Contact_ID and a number field for Tournament_ID).

I want to be able to open a Tournament form with a contacts subform, select an official and assign them to the tournament. I also want to be able to do it the other way (open a contact form with a tournemant subform).

I can get the subform to view

Umpires may get appointed to multiple tournaments ... tournaments will have multiple officials.

I will then build reports that show by tournament or by official.

Any assistance greatly appreciated.
 

plog

Banishment Pending
Local time
Today, 06:14
Joined
May 11, 2011
Messages
11,646
Your not quite ready for forms.

You need 3 tables like so:

Tournaments
tourn_ID, auto number, primary key
...other fields for tournament info

Contacts
con_ID, auto number, primary key
...other fields for contact info

TournamentContacts
tc_ID, auto number, primary key
ID_Contact, number, foreign key to Contacts
ID_Tournament, number, foreign key to Tournaments

TournamentContacts is where you assign tournaments to contacts and vice versa, not in the other tables. Then, TournamentContacts can become the basis of subforms that appear on the forms based on Tournaments and Contacts.
 

SwampyNZ

New member
Local time
Today, 21:14
Joined
Jan 9, 2024
Messages
11
Thank you, let me play with that.
 

SwampyNZ

New member
Local time
Today, 21:14
Joined
Jan 9, 2024
Messages
11
Your not quite ready for forms.

You need 3 tables like so:

Tournaments
tourn_ID, auto number, primary key
...other fields for tournament info

Contacts
con_ID, auto number, primary key
...other fields for contact info

TournamentContacts
tc_ID, auto number, primary key
ID_Contact, number, foreign key to Contacts
ID_Tournament, number, foreign key to Tournaments

TournamentContacts is where you assign tournaments to contacts and vice versa, not in the other tables. Then, TournamentContacts can become the basis of subforms that appear on the forms based on Tournaments and Contacts.
OK, so I have created that table.

So how do I create the Form: Tournament - Subform Contact (as I need to see some of the the contact detail) and then how do I select a contact to appoint to that tournament?
 

plog

Banishment Pending
Local time
Today, 06:14
Joined
May 11, 2011
Messages
11,646
Build a form based on Tournaments and make it work with just a single record at a time (Default View -> Single Form). Make it have inputs for every field so you can add/edit everything in Tournaments.

Build a form based on TournamentContacts and make it work with multiple records (Default View -> Continous Form). Make it have a single drop down input that uses ID_Contact but displays other data from that same record. This link should help for that.


When both forms are done you place the TournamentContacts form on Tournaments and bind them. This link should hlep for that:


That will allow you to add Contacts to tournaments. You can also use the same method above to build 2 forms to add Tournaments to Contacts.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:14
Joined
Feb 19, 2002
Messages
43,275
This is a many-to-many relationship. To implement this type of relationship requires what is commonly referred to as a junction table. Frequently, the only two columns in this table would be the FK to the contacts table and the FK to the Tournaments table. In this situation, the PK of the junction table would be a compound PK. To make one, select the first column and then the second column and press the PK button. Both columns will show the PK icon. To see what this actually looks like, open the indexes dialog.

In other situations, you might want to add an autonumber as the PK for the junction table but you would STILL need a unique index on the two field that make the junction unique. Look at the indexes dialog in the first example to see the technique for creating a multi-column unique index. In still other situations, you might need intersection data. For example, if you wanted to know the date that the contact was assigned to the tournament, you would add the date field here. It can't go in the Tournament table because each row in the tournament table indicates one specific tournament and has nothing to do with contacts. It can't go in the Contacts table for the same reason. There is no tournament ID in the contacts table because contacts stand alone. It is the intersection of Contact and Tournament that gives you the unique identifier which defines the date field.

Here is a m-m sample. It is not your specific relationship but hopefully you will be able to make the transition. This sample shows you how to work with a m-m from either direction and uses two different styles of forms just to show the options. From your perspective, either the subform or the popup form might make more sense in a different situation. Or you might choose to use subforms in both cases or popups in both cases.

 

mike60smart

Registered User.
Local time
Today, 12:14
Joined
Aug 6, 2017
Messages
1,905
OK, so I have created that table.

So how do I create the Form: Tournament - Subform Contact (as I need to see some of the the contact detail) and then how do I select a contact to appoint to that tournament?
Hi
When you create your Forms as suggested by Plog, upload the database so we can check it for you.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:14
Joined
May 7, 2009
Messages
19,243
i made another table (Tournament Players) and made query on it (query1).
made a form for query1 and use it as subform of Appointment Main.
 

Attachments

  • WMH Officials v0.1.accdb
    2.9 MB · Views: 39

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:14
Joined
May 7, 2009
Messages
19,243
i just noticed that the form is for Tournament Officials, therefore rename your New table as "Tournament Officials" (not players).
if you want some details, you can add a Team table:

Team table:
Team_ID (Auto) (PK)
Country Code (Long)
Team Name
Team Manager
..etc (other info about the team)

Player table:
Player_ID (PK, Primary Key)
Team_ID
Player Name
Ranking (World ranking? etc.)
..(Other info)

For each Tournament, there should be Stats for each Team Players:

Tournament Player table:
TourID (Auto) (PK)
Tournamen_ID (Long, FK to Tournament)(FK - Foreign Key)
Player_ID (Long, FK to player table)
Time Played (date, short time)
Goals (Integer)

I can't imagine what other info you need, but I am sure you all got it all on your list.
goodluck with your project.
 

Users who are viewing this thread

Top Bottom