Tried to replicate you problem and this is what I have done.
I have a table (Table5)with the following Fields:
1) ID (PK Auto Number)
2) Arrival_Time (Date/Time)
3)Time_ Departure (Date/Time)
Assumptions:
1) A person will be considered to be departed if the Time_Departure is Not Null. e.g. if departure time is entered the person is considered to have left.
What Have I Done:
I have a Simple Form data Source is Table5. I have added three Text Box controls:
1) Text0
2) Text2
3) Text6
I have attached a code To the Open Event of the form which sets the value of Text0 with Current Time. I have then attached a Code to the Timer event.
Me.Text2 = Format(Time, "hh:mm:ss AMPM") This line of the code is not essential and I have used it to show the current time being updated. You can omit this line and not keep Text2 on your form.
The main aim is to create a interval of 10 minutes. Therefore when you open form the initialtime=Me.text0 which is the time at which the form is opened.
timediff is the difference between initial time and current time. When the difference = 10 the code updates the initial time with current time making the difference 0. In this way a continuous time period of 10 minutes interval is created.
When timediff=10 the procedure Total_present is called. This procedure uses a DAO.Recordset loops through Table5. A counter variable intCounter is introduced and +1 is done to it when ever the Do While Loop encounters the condition isNull(rst!Time_Departure) the result is then used to update Text6. This is done at an interval of 10 minutes. The codes used as follows:
Code:
Private Sub Form_Open(Cancel As Integer)
Me.Text0 = Format(Now, "hh:mm:ss AMPM")
End Sub
Private Sub Form_Timer()
Dim timeDiff As Integer
Dim initialTime As Date
Me.Text2 = Format(Time, "hh:mm:ss AMPM")
initialTime = Format(Me.Text0, "hh:mm:ss AMPM")
timeDiff = DateDiff("n", initialTime, Format(Now, "hh:mm:ss AMPM"))
If timeDiff = 1 Then
initialTime = Format(Now, "hh:mm:ss AMPM")
Me.Text0 = initialTime
Call Total_Present
End If
End Sub
Private Sub Total_Present()
Dim rst As DAO.Recordset
Dim intCounter As Integer
Set rst = CurrentDb.OpenRecordset("Table5")
Do While Not rst.EOF
If IsNull(rst!Time_Departure) Then
intCounter = intCounter + 1
End If
rst.MoveNext
Loop
Set rst = Nothing
Me.Text6 = intCounter
intCounter = 0
End Sub