Syncing employee list with activities during the week many to many relationship

Viewed 24

I have a form where you choose the employees in a dropdown continous form.(From tblEmployee) that worked this week and store them in TSLabor table. In another form I track what activities were done during the days of the week (could have multiple activities for any given day) in tblActivities. In this form I have a sub form list of all the employees who are in tsLabor for this week. This way the user can input the hours for each employee. (Not all employees will have hours in every activity, but I can handle zero hours.) These records are stored in tsActivityLabor. I add a record for each employee in the TSLabor table with the activityID it each time a new activity record is created.

User can not add/delete in the subfom, but they can in the First form. My issue is how do I add/Delete from the tsActivityLabor table (for each activityID) when an employee is added/deleted from the First form.

I need to check to see if the employee has a record for each activityID for that week. If not add it.

Right now I create a record set of activityIDs for the week from tblActivities. I then create another recordset from the tblTSLabor of all the employees in that week. I then take each ActivityID from the first recordset and create a third recordset of all the employees for that ActivityID in the tsActivityLabor table. I then verify that each employee from the second recordset has a record in the third recordset.

There has to be a quicker way of doing this but I can't figure it out. One thought is to create an update query that could look at the tsActivityLabor table and verify that there is an employee record for each employee for each activity. Researched but can't find any examples of a query like this. any help would be appreciated. Adolph

1 Answers

In short when queries underlying forms get complicated Access doesn't know how to update the tables and so chooses not to try.
https://docs.microsoft.com/en-us/office/troubleshoot/access/errors-updating-query-form-data

This is not a problem for your case as the TSLabor table in your example can be replaced by a date column in the TSActivityLabor Table. Access is supposed to be user friendly so I'm going to suggest a workflow that lets access help. here is an example:
create the following tables and hook up the relationships under the Database Tools-Relationships Tab.

Relationships

Now click on any table and hit create form and access will create a working form which properly updates the tables. Here is the form after hitting the Employee table:

Employee Form

Because we set up the relationships in advance Access automatically added the many side of the relationship as a subform. Play with the highlighted record selectors to see how to cycle through records and add new ones. Next we Start improving the forms. In the EmployeeActivity Form I Replaced Foreign Keys with combo boxes, removed the ID which the user should never see and added an unbound combobox to filter the records. enter image description here

P.S. if the weekly Activities is still a thing Relate Activities to employees through a weeklyactivities table (a type of super many to many relationship).

Related