Query or Code - Can You help pleeeese
I posted this question a few weeks ago and did not get much / any response probably because my Q was unclear – I have reworded it - sorry it is long but not complicated.
An entry scanner provides 2 lines of raw data per employee each day. Using a query I use the Max of punch for the Out time and Min of punch for the In time. This is done by a query.
01/20/02 JoeNightWorker; Shift2; Punch 240
01/20/02; JoeDayWorker; Shift1; Punch 360
01/20/02; JoeDayWorker; Shift1; Punch 960
01/20/02; JoeNightWorker; Shift2; Punch 1080
01/21/02; JoeNightWorker; Shift2; Punch 240
The dayshift is easy, using MaxofPunch and MinofPunch - JoeDayWorker entered 360 minutes after midnight on 01/20/02 (6am) and that he left 600 minutes later at 960 minutes after midnight (4pm) on 01/20/02.
Nightshift is my problem. JoeNightWorker arrived at 6pm, 01/20 and left the following morning at 4am, 01/21. Following the same rules as for shift 1 would provide that he clocked in at 4am and went home at 6pm. The time difference is correct but it is based on the wrong pair of punches as we would find out on Monday when there would be no out punch for the Sunday night when we don't work. MY problem is not calculating a time difference BUT camparing the right pair of punches.
My guess at a solution is as follows: When the shift = 2, use the Max of Punch of [ReportDate] as the InPunch and the Min of Punch of the [Report Date]+1 (tomorrow) as the OutPunch. This way I would be reading the correct In and Out Punch pair.
I can’t work this out in a query and so if I knew what I was doing I would write the following in real code and put it somewhere.
If shift = 1 then
PunchDate = ReportDate
InTime = MinofPunchTime
Outtime = MaxofPunchtime
else '(shift=2)
PunchDate = ReportDate
InTime =MaxOfPunchTime
PunchDate=ReportDate+1
OutTime=MinofPunchTime
Trouble is I don’t know how to write the code or where to put it or call it. Any help appreciated.
Many thanks.
I posted this question a few weeks ago and did not get much / any response probably because my Q was unclear – I have reworded it - sorry it is long but not complicated.
An entry scanner provides 2 lines of raw data per employee each day. Using a query I use the Max of punch for the Out time and Min of punch for the In time. This is done by a query.
01/20/02 JoeNightWorker; Shift2; Punch 240
01/20/02; JoeDayWorker; Shift1; Punch 360
01/20/02; JoeDayWorker; Shift1; Punch 960
01/20/02; JoeNightWorker; Shift2; Punch 1080
01/21/02; JoeNightWorker; Shift2; Punch 240
The dayshift is easy, using MaxofPunch and MinofPunch - JoeDayWorker entered 360 minutes after midnight on 01/20/02 (6am) and that he left 600 minutes later at 960 minutes after midnight (4pm) on 01/20/02.
Nightshift is my problem. JoeNightWorker arrived at 6pm, 01/20 and left the following morning at 4am, 01/21. Following the same rules as for shift 1 would provide that he clocked in at 4am and went home at 6pm. The time difference is correct but it is based on the wrong pair of punches as we would find out on Monday when there would be no out punch for the Sunday night when we don't work. MY problem is not calculating a time difference BUT camparing the right pair of punches.
My guess at a solution is as follows: When the shift = 2, use the Max of Punch of [ReportDate] as the InPunch and the Min of Punch of the [Report Date]+1 (tomorrow) as the OutPunch. This way I would be reading the correct In and Out Punch pair.
I can’t work this out in a query and so if I knew what I was doing I would write the following in real code and put it somewhere.
If shift = 1 then
PunchDate = ReportDate
InTime = MinofPunchTime
Outtime = MaxofPunchtime
else '(shift=2)
PunchDate = ReportDate
InTime =MaxOfPunchTime
PunchDate=ReportDate+1
OutTime=MinofPunchTime
Trouble is I don’t know how to write the code or where to put it or call it. Any help appreciated.
Many thanks.
Last edited: