Hey folks. As you probably imagine, I get a TON of questions every day from people asking how to do things in Access. I'm going to try to start picking one question every day and posting my answer here. Today's question comes from one of my students, David. He asks:
I'm using Access 2010. I have an Employee Table with Employees and an Event Table where I need 4 employees for every event. So I have 4 fields in the event table called "Staff1", "Staff2", "Staff3", "Staff4" and they are set to be a number of type long integer so that they are essentially all foreign keys to the primary key "EmployeeID" autonumber in the EmployeeT.
Now I'd like to make a query that shows me each event per row. I've added the 4 "Staff" fields from the EventT but naturally they are just numbers. How do I see the names associated with those numbers from the EmployeeT? Normally I would just add the Employee Name field from the EmployeeT and make sure the primary key and foreign key are related. However since all four of those foreign keys are related to the same primary key, the query is turning up empty when I run it.
The end goal is to create a report that shows each event and shows the 4 Staff names of the four employees assigned to the event. Thanks!
Hi David.
Whenever you have more than ONE of something, you really should move that SOMETHING to a separate table. Here, for example, you should have an EventT table, an EmployeesT table, and then an EventXEmployeesT cross-reference table where you can track which employees are in which event. This is a classic MANY TO MANY relationship. Each event can have multiple employees, and each employee can belong to more than one event.
I would make an event form based on the EventT table, and then have a subform based on the EventXEmployeeT table. In that subform, you would have combo boxes that are based on the EmployeeT table to select the employees for the event. You could also go backwards and show a subform on each employee's record for which events they're in. I cover this in Access Expert 7.
Once you've got this set up properly, it would be easy to create a report where you could design a GROUPING LEVEL level for the event, and then in the details show all of the employees. Again, covered in Access Expert 7. Review that lesson, and then if you still have questions, let me know.
Richard