DB structure best practice question
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
DB structure best practice question
Currently I have a separate table for 4 variables that a contact can be "assigned" to in our organization - role (many possible), funding (one), location (one), and program (many). I have set up a junction table for each of these and that works well, but as I was working on a form for input, I realized I could have one junction table for all four of these tables. Is that sensible? I mean, is there any inherent flaw in that design that would cause me trouble down the road.
If I have one junction table, instead of using multiple subforms on my main form, I could use just one subform with combo boxes for each of those variables that need to be set right?
If I have one junction table, instead of using multiple subforms on my main form, I could use just one subform with combo boxes for each of those variables that need to be set right?
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DB structure best practice question
If only one funding and one location can be assigned to a contact, you don't need junction tables for those - the contacts table can contain a funding field and a location field. On the form(s) bound to the contacts table, use combo boxes bound to these fields.
I assume that the roles and programs of a contact are independent of each other. Therefore, you need two separate junction tables for these, and two separate subforms bound to these junction tables.
I assume that the roles and programs of a contact are independent of each other. Therefore, you need two separate junction tables for these, and two separate subforms bound to these junction tables.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
Ok, that makes sense. ThanksHansV wrote:If only one funding and one location can be assigned to a contact, you don't need junction tables for those - the contacts table can contain a funding field and a location field. On the form(s) bound to the contacts table, use combo boxes bound to these fields.
I assume that the roles and programs of a contact are independent of each other. Therefore, you need two separate junction tables for these, and two separate subforms bound to these junction tables.
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
Next question...to match people with assignments where an assignment may have more then one person, should I treat assignments as the one side of relationship and build a form/subform (like my original contact form) where I enter the basic data of the assignment i.e. id#, program, location, start date, and then choose all contacts for that assignment from a combo on subform, or even with chk boxes like I did with roles? OR, is it best to come at this from the people side, i.e. continue on my Contact form with a subform for entering assignments. The first way seems to me to have the advantage of being able to assign several people with one whack through the checklist or combo, where as with the latter way, if I was assigning more than one person, I'd have to go to each persons record.
Whew, I hope that makes sense.
Whew, I hope that makes sense.
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DB structure best practice question
Why not offer both?
When you are creating or editing an assignment, it is convenient to use a main form based on the assignment table, with a subform to select/deselect contacts.
When you are creating or editing a contact, it is more convenient to use a main form based on the contact table, with a subform to select/deselect assignments.
When you are creating or editing an assignment, it is convenient to use a main form based on the assignment table, with a subform to select/deselect contacts.
When you are creating or editing a contact, it is more convenient to use a main form based on the contact table, with a subform to select/deselect assignments.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
That's a great idea! I'll take a whack at this and let you know if I get it working. :)HansV wrote:Why not offer both?
When you are creating or editing an assignment, it is convenient to use a main form based on the assignment table, with a subform to select/deselect contacts.
When you are creating or editing a contact, it is more convenient to use a main form based on the contact table, with a subform to select/deselect assignments.
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
Arggh...now I am having trouble figuring out structure for this. Could be my brain is tired. I have (main) frmAsgn based on assignment table and sbfrmContact which has a multiselect listbox on it getting values from qryContact (so that I can later filter out archived contacts). Does that sound right. It's not working but again, my brain is tired and I may be missing something. I'm not sure what if anything the subform should be based on. Sorry to sound so dense.NWGal wrote:That's a great idea! I'll take a whack at this and let you know if I get it working. :)HansV wrote:Why not offer both?
When you are creating or editing an assignment, it is convenient to use a main form based on the assignment table, with a subform to select/deselect contacts.
When you are creating or editing a contact, it is more convenient to use a main form based on the contact table, with a subform to select/deselect assignments.
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DB structure best practice question
The easiest way is to create a continuous (or datasheet) subform bound to the junction table or to a query based on the junction table.
The subform would be linked to the main form by AssignmentID (or whatever you call the primary key of the assignment table, and it would contain a combo box bound to the ContactID field (or whatever you call the primary key of the contact table).
This setup doesn't require VBA code, at least not for its basic operation.
As an alternative to a subform, you could use a multi-select list box directly on the main form itself. The list box would be unbound, and its Row Source would be the contact table or a query based on the contact table. VBA code is needed to add records to the junction table or remove them when items in the list box are selected/deselected.
The attached sample database demonstrates both approaches in a students/classes setting.
The subform would be linked to the main form by AssignmentID (or whatever you call the primary key of the assignment table, and it would contain a combo box bound to the ContactID field (or whatever you call the primary key of the contact table).
This setup doesn't require VBA code, at least not for its basic operation.
As an alternative to a subform, you could use a multi-select list box directly on the main form itself. The list box would be unbound, and its Row Source would be the contact table or a query based on the contact table. VBA code is needed to add records to the junction table or remove them when items in the list box are selected/deselected.
The attached sample database demonstrates both approaches in a students/classes setting.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
Hi,HansV wrote:The easiest way is to create a continuous (or datasheet) subform bound to the junction table or to a query based on the junction table.
The subform would be linked to the main form by AssignmentID (or whatever you call the primary key of the assignment table, and it would contain a combo box bound to the ContactID field (or whatever you call the primary key of the contact table).
This setup doesn't require VBA code, at least not for its basic operation.
As an alternative to a subform, you could use a multi-select list box directly on the main form itself. The list box would be unbound, and its Row Source would be the contact table or a query based on the contact table. VBA code is needed to add records to the junction table or remove them when items in the list box are selected/deselected.
The attached sample database demonstrates both approaches in a students/classes setting.
I know it's been a little bit since this post, but I just got back to working on this again. I am trying the subform route, and I can see it will work fine, however, if I want to also include the roleId in the assignment junction table, how do I get that piece. The reason I need to do this is that although every person can have several roles, when it comes to my assignments, for reporting I need to break out the assignment by roles. It would be the equivalent of the Student class sample needing to have a report which separated out boys and girls, if that made sense.
Thanks
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DB structure best practice question
Are roles linked to assignments? For example, contact A has role K in connection with assignment V and roles L and M in connection with assignment W? Or are roles and assignments independent of each other.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
Yes, on an assignment the person can be in one role or the other. So A can definitely be in Role K, on one assignment, but Role L on another.HansV wrote:Are roles linked to assignments? For example, contact A has role K in connection with assignment V and roles L and M in connection with assignment W? Or are roles and assignments independent of each other.
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
I should add that I have queries made to look at contacts by roles.NWGal wrote:Yes, on an assignment the person can be in one role or the other. So A can definitely be in Role K, on one assignment, but Role L on another.HansV wrote:Are roles linked to assignments? For example, contact A has role K in connection with assignment V and roles L and M in connection with assignment W? Or are roles and assignments independent of each other.
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DB structure best practice question
Can a contact have more than one role for one assignment, or just one?
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
No, when a contact gets an assignment he or she has a specific role on that assignment. This is one reason I chose to have assignments be the one side of a one to many relationship.HansV wrote:Can a contact have more than one role for one assignment, or just one?
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DB structure best practice question
OK, then you can add a field RoleID to the contacts-assignments junction table, and create a combo box bound to this field on the subform, with the Roles table as Row Source.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
Ok, is there a way to have the role that is already assigned to the contact be a part of the contact combo, so that I don't need to have an extra step. I've already taken the step of actually having two combo boxes, one for role A (always only one contact), and one for role B, can be one, or two people. Each combo gets it's data from it's respective query. Hope that makes sense.HansV wrote:OK, then you can add a field RoleID to the contacts-assignments junction table, and create a combo box bound to this field on the subform, with the Roles table as Row Source.
Edited to add - all 2 or 3 contacts are showing up in the junction table, so that is all good :)
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
No, because I have the contactids showing up, but not with their roleIdHansV wrote:So is your problem solved now?
-
- Administrator
- Posts: 78528
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DB structure best practice question
Could you post a sample database (zipped)? I have to admit that I can't visualize the current situation any more.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 198
- Joined: 21 Aug 2011, 02:32
Re: DB structure best practice question
Here you go, I saved as a dummy db and deleted fields in my contacts table with identifying info, so don't be alarmed by the name errors in the form.
You do not have the required permissions to view the files attached to this post.