Hello all,
I'm hoping for some more pointers on table design as I start to build my database up.
The relevant parts of the database for my current problem area are:
tblSHIFT - a table recording each workshift performed. This table includes the following fields:
ShiftID - primary key
ShiftStartTime
ShiftStopTime
tblCREW - a table recording the 2 employees who work each shift. This table includes the following fields:
CrewID - primary key
ShiftID - foreign key
EmployeeID
Current Issue: What I also need to do is keep track of how much rest each employee got between workshifts.
My thoughts are to add a new field to tblCREW which is a calculated field taking the difference between the previous shift's ShiftStopTime and the current shift's ShiftStartTime (both are fields stored in the parent table tblSHIFT).
The 'ingredients' I'm thinking I need to accomplish this are:
1. Find the last shift worked by that employee.
- create a variable to store the current employeeID
- Create a recordset of tblCREW
- Filter the recordset to the current tblCREW.EmployeeID
- Sort by tblSHIFT.ShiftStopTime (can't sort on tblCREW.ID because they may be added out of chronological order)
- Move to the appropriate first/last record (depending on ASC / DESC) to get that ShiftStopTime
- Store the retrieved previous ShiftStopTime in another variable
2. Do the calculation.
3. Set it to run everytime the tblCREW.EmployeeID changes, or the previous tblSHIFT.ShiftStopTime / current tblSHIFT.ShiftStartTime changes.
I'm not even sure this is the right way to go about it, but if it is I'm not sure how to make this incomplete list of ingredients into the right recipe. I'm very new to Access and VBA, which means I'm sketchy on matters like the use of multiple recordsets (the above references 2 tables) etc.
If anyone can offer any help it will be very much appreciated.
I'm hoping for some more pointers on table design as I start to build my database up.
The relevant parts of the database for my current problem area are:
tblSHIFT - a table recording each workshift performed. This table includes the following fields:
ShiftID - primary key
ShiftStartTime
ShiftStopTime
tblCREW - a table recording the 2 employees who work each shift. This table includes the following fields:
CrewID - primary key
ShiftID - foreign key
EmployeeID
Current Issue: What I also need to do is keep track of how much rest each employee got between workshifts.
My thoughts are to add a new field to tblCREW which is a calculated field taking the difference between the previous shift's ShiftStopTime and the current shift's ShiftStartTime (both are fields stored in the parent table tblSHIFT).
The 'ingredients' I'm thinking I need to accomplish this are:
1. Find the last shift worked by that employee.
- create a variable to store the current employeeID
- Create a recordset of tblCREW
- Filter the recordset to the current tblCREW.EmployeeID
- Sort by tblSHIFT.ShiftStopTime (can't sort on tblCREW.ID because they may be added out of chronological order)
- Move to the appropriate first/last record (depending on ASC / DESC) to get that ShiftStopTime
- Store the retrieved previous ShiftStopTime in another variable
2. Do the calculation.
3. Set it to run everytime the tblCREW.EmployeeID changes, or the previous tblSHIFT.ShiftStopTime / current tblSHIFT.ShiftStartTime changes.
I'm not even sure this is the right way to go about it, but if it is I'm not sure how to make this incomplete list of ingredients into the right recipe. I'm very new to Access and VBA, which means I'm sketchy on matters like the use of multiple recordsets (the above references 2 tables) etc.
If anyone can offer any help it will be very much appreciated.