I'm new to Access, so please be patient.
I'm trying to write an expresion that will work out how many hours were missed from a given shift, using the start and finish times, how long the shift was ment to be, and how many staff showed up compared to how many were ment to.
The expression is getting hugely complicated to type in a text fiel on a form, there must be an easier way, please help.
I'm familiar with java but not VBA or SQL. I'm not sure if an expresion is the best way to tackle this, should I use the VBAEditor or a macro? If so how?
My expression so far (it's laid out like this in the hope of making it easier to understand):
=IIf(
[StaffReq]>=4 And IsNull([Staff4PIN]), //If 4 staff are req but there's no entry for the 4th member of staff...
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]"), //... then the whole shift is missed, get shift length form lookup table.
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]") //else, work out missed hours (shift length minus worked hours) Get Shift length
- //Minus
IIf( //Work out number of hours worked
[S4Type]="Day", //If it's a day shift...
DateDiff("h",[Staff4StartTime],[Staff4FinishTime]),//...then start time and finish time will be on the same day, so work out the difference between the two
IIf( // else it's a night shift, start time will be larger than finish time so DateDiff() won't know it's over two days and will return -ve no.
[Staff4FinishTime]<12:00,//If finish time is less than 12:00, the shift must have finished the day after it started, therefore work out the hours worked before 00:00 on the first day added to the hours worked after 00:00 on the second day.
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]")//Find out how many ours were ment to be worked, ready to minus the worked hours from it.
-minus
( DateDiff("h", "00:00", [Staff4FinishTime]) + DateDiff("h",[Staff1StartTime],"00:00")) ,//Add the time worked before 0000 to the time worked after 0000
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]")-DateDiff("h",[Staff4FinishTime],[Staff4StartTime])//If finish time is greter than 12:00, the shift finished on the same day it started, so normal shift lenght minus DateDiff() calc will work.
)
)
)
I'm trying to write an expresion that will work out how many hours were missed from a given shift, using the start and finish times, how long the shift was ment to be, and how many staff showed up compared to how many were ment to.
The expression is getting hugely complicated to type in a text fiel on a form, there must be an easier way, please help.
I'm familiar with java but not VBA or SQL. I'm not sure if an expresion is the best way to tackle this, should I use the VBAEditor or a macro? If so how?
My expression so far (it's laid out like this in the hope of making it easier to understand):
=IIf(
[StaffReq]>=4 And IsNull([Staff4PIN]), //If 4 staff are req but there's no entry for the 4th member of staff...
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]"), //... then the whole shift is missed, get shift length form lookup table.
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]") //else, work out missed hours (shift length minus worked hours) Get Shift length
- //Minus
IIf( //Work out number of hours worked
[S4Type]="Day", //If it's a day shift...
DateDiff("h",[Staff4StartTime],[Staff4FinishTime]),//...then start time and finish time will be on the same day, so work out the difference between the two
IIf( // else it's a night shift, start time will be larger than finish time so DateDiff() won't know it's over two days and will return -ve no.
[Staff4FinishTime]<12:00,//If finish time is less than 12:00, the shift must have finished the day after it started, therefore work out the hours worked before 00:00 on the first day added to the hours worked after 00:00 on the second day.
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]")//Find out how many ours were ment to be worked, ready to minus the worked hours from it.
-minus
( DateDiff("h", "00:00", [Staff4FinishTime]) + DateDiff("h",[Staff1StartTime],"00:00")) ,//Add the time worked before 0000 to the time worked after 0000
DLookUp("[ShiftLength]","WorkedShiftTypeLookUp","[S4Type]=[ShiftType]")-DateDiff("h",[Staff4FinishTime],[Staff4StartTime])//If finish time is greter than 12:00, the shift finished on the same day it started, so normal shift lenght minus DateDiff() calc will work.
)
)
)
Last edited: