Ok... first I changed your dataset to be more normalized
In other words the OPERATOR I replaced with a field called OPERATOR_ID (FK to an operators table with an autonumber fields as the PK)
I changed PROCESS to PROCESS_ID (same concept as the operator, but really irrelevant for this example, just my own neuroses)
this is the code I used:
Code:
Dim db As Database
Dim rst_People As Recordset
Dim iOperatorID As Long
Dim rst_Dates As Recordset
Dim dCurrDate As Date
Dim rst_Functions As Recordset
Dim dPrevTime As Date
Dim dCurrTime As Date
Dim iTimeDiff As Long
Set db = CurrentDb
Set rst_People = db.OpenRecordset("SELECT Operator_ID FROM tblTest GROUP BY Operator_ID")
rst_People.MoveFirst
Do While rst_People.EOF <> True
iOperatorID = rst_People.Fields("Operator_ID")
Debug.Print iOperatorID
Set rst_Dates = db.OpenRecordset("SELECT format(Fun_Date, ""Short Date"") as CurrDate FROM tblTest WHERE (Operator_ID = " & iOperatorID & ") GROUP BY Format(Fun_Date, ""Short Date"")")
rst_Dates.MoveFirst
Do While rst_Dates.EOF <> True
dCurrDate = rst_Dates.Fields("CurrDate")
Debug.Print " " & dCurrDate
Set rst_Functions = db.OpenRecordset("SELECT * FROM tblTest WHERE Operator_ID = " & iOperatorID & " AND format(fun_Date, ""Short Date"") = #" & dCurrDate & "# ORDER BY Fun_Date DESC")
rst_Functions.MoveFirst
dPrevTime = rst_Functions.Fields("fun_date")
Do While rst_Functions.EOF <> True
dCurrTime = rst_Functions.Fields("fun_Date")
iTimeDiff = DateDiff("s", dCurrTime, dPrevTime)
rst_Functions.Edit
If iTimeDiff = 0 Or iTimeDiff > 300 Then
rst_Functions!elapsed = 100
Else
rst_Functions!elapsed = iTimeDiff
End If
rst_Functions.Update
Debug.Print " " & rst_Functions.Fields("fun_Date")
Debug.Print " " & iTimeDiff
rst_Functions.MoveNext
dPrevTime = dCurrTime
Loop
rst_Functions.Close
rst_Dates.MoveNext
Loop
rst_Dates.Close
rst_People.MoveNext
Loop
rst_People.Close
Set db = Nothing
I left some debug.print statements in there so you can open the immediate window and see some statements as it's progressing, you can also add some debug.print statements to see the SQL statements if you want.
What this does is cycles through all your individual operators represented in your table.
For each operator represented it cycles through each day the person was active
For each day the operator was active it cycles through their timestamped records in DESCENDING order, always evaluating the last record as 100 and each record prior to that one by a number of seconds = 100 if the value for the time difference is greater than 300 seconds and the actual time difference if it's less than 300 seconds.