Here goes~
I am trying to build a table containing
EmpNo
Name
TimeIn
TimeOut
TimeStamp
Date
The employee clocks in, a record is created and has a timestamp.
The employee clocks out, a record is created and has a timestamp.
They can clock in and out several times during the day. The main table will be where "every" employee's In and Out will be stored.
I'm creating a Time Sheet for the them to view the In and Out, but I need to get the In and Out on the same record according to the date.
So far, I've made a query to create a EmpLog table according to who is logged in. From this, I need to get the records on one record according to date.
The Code is:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Option Compare Database
Public TimeLOGIn As ADODB.Recordset
Public EmpFinalTimeLog As ADODB.Recordset
Private Sub Command2_Click()
'------------------------------------------------------------
DoCmd.SetWarnings False
'------------------------------------------------------------
' Run Query to clear out table
'------------------------------------------------------------
DoCmd.OpenQuery "qryClearEmpLog", acNormal, acEdit
DoCmd.OpenQuery "qryClrTimeLogOUTTable", acNormal, acEdit
DoCmd.OpenQuery "MakeTimeLogEmp", acNormal, acEdit
'------------------------------------------------------------
' Open TimeLOGIn Table
'------------------------------------------------------------
Set TimeLOGIn = New ADODB.Recordset
TimeLOGIn.Open "Timelogin", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'------------------------------------------------------------
' READ First Record of the TimeLOGIn Table
'------------------------------------------------------------
TimeLOGIn.MoveFirst
'------------------------------------------------------------
' READ TimeLOGIn Table is EOF
'------------------------------------------------------------
Do Until TimeLOGIn.EOF
'------------------------------------------------------------
' Open EmpFinalTimeLog Table
'------------------------------------------------------------
Set EmpFinalTimeLog = New ADODB.Recordset
EmpFinalTimeLog.Open "EmpFinalTimeLog", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
TimeLOGIn.MoveNext
'------------------------------------------------------------
' This will add a new record
'------------------------------------------------------------
EmpFinalTimeLog.AddNew
'------------------------------------------------------------
' If Timeout field is = to 12:00 AM
'------------------------------------------------------------
If TimeLOGIn.Fields("TimeOut"
= #12:00:00 AM# Then
'------------------------------------------------------------
' Move fields from Login record to fields in the Logout record
'------------------------------------------------------------
EmpFinalTimeLog.Fields("TimeStamp"
= TimeLOGIn.Fields("TimeStamp"
EmpFinalTimeLog.Fields("EmpNo"
= TimeLOGIn.Fields("Empno"
EmpFinalTimeLog.Fields("Name"
= TimeLOGIn.Fields("Name"
EmpFinalTimeLog.Fields("TimeIn"
= TimeLOGIn.Fields("TimeIn"
EmpFinalTimeLog.Fields("Date"
= TimeLOGIn.Fields("Date"
'------------------------------------------------------------
' Read next record in the TimeLOGIn Table
'------------------------------------------------------------
TimeLOGIn.MoveNext
'------------------------------------------------------------
' if TimeLOGIn is EOF then update EmpFinalTimeLog table and goto end of program
'------------------------------------------------------------
If TimeLOGIn.EOF Then
EmpFinalTimeLog.Update
GoTo 50
Else
End If
'------------------------------------------------------------
' If not EOF and TimeOut field in LOGIn record is not equal
' to 12:00 AM then update LOGOut field TimeOut with TimeOut
' field in the LOGIn record
' then update the LOGOut table
'------------------------------------------------------------
If TimeLOGIn.Fields("TimeOut"
<> #12:00:00 AM# Then
EmpFinalTimeLog.Fields("TimeOut"
= TimeLOGIn.Fields("TimeOut"
EmpFinalTimeLog.Update
End If
'------------------------------------------------------------
' Read next record in the TimeLOGIn Table
'------------------------------------------------------------
TimeLOGIn.MoveNext
If TimeLOGIn.EOF Then GoTo 50
End If
Loop
50
TimeLOGIn.Close
MsgBox ("File Has Been Updated"
End Sub
Private Sub OK_Click()
On Error GoTo Err_OK_Click
DoCmd.Close
Exit_OK_Click:
Exit Sub
Err_OK_Click:
MsgBox err.Description
Resume Exit_OK_Click
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This is ran from a button on a form, for now.
This sample is from the table it gets the info from:
TimeStamp EmpNo Name TimeIN TimeOut Date
2/3/2004 5:23:20 PM 1184 Tanya 5:30:00 AM 12:00:00 AM 2/3/2004
2/3/2004 5:23:23 PM 1184 Tanya 12:00:00 AM 5:45:00 PM 2/3/2004
2/3/2004 5:23:26 PM 1184 Tanya 6:30:00 PM 2:00:00 AM 2/3/2004
2/3/2004 5:23:29 PM 1184 Tanya 12:00:00 AM 6:45:00 PM 2/3/2004
2/3/2004 5:23:31 PM 1184 Tanya 8:30:00 PM 12:00:00 AM 2/3/2004
2/3/2004 5:23:33 PM 1184 Tanya 12:00:00 AM 10:30:00 PM 2/3/2004
2/4/2004 5:37:58 PM 1184 Tanya 5:30:00 PM 12:00:00 AM 02/4/2004
2/4/2004 5:41:49 PM 1184 Tanya 12:00:00 AM 5:45:00 PM 2/4/2004
2/4/2004 6:14:17 PM 1184 Tanya 6:15:00 PM 12:00:00 AM 2/4/2004
My results:
TimeStamp EmpNo Name TimeIN TimeOut Date
2/4/2004 5:37:58 PM 1184 Tanya 5:30:00 PM 10:30:00 PM 2/4/2004
2/3/2004 5:23:26 PM 1184 Tanya 6:30:00 PM 5:45:00 PM 2/3/2004
I'd appreciate any help!
I am trying to build a table containing
EmpNo
Name
TimeIn
TimeOut
TimeStamp
Date
The employee clocks in, a record is created and has a timestamp.
The employee clocks out, a record is created and has a timestamp.
They can clock in and out several times during the day. The main table will be where "every" employee's In and Out will be stored.
I'm creating a Time Sheet for the them to view the In and Out, but I need to get the In and Out on the same record according to the date.
So far, I've made a query to create a EmpLog table according to who is logged in. From this, I need to get the records on one record according to date.
The Code is:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Option Compare Database
Public TimeLOGIn As ADODB.Recordset
Public EmpFinalTimeLog As ADODB.Recordset
Private Sub Command2_Click()
'------------------------------------------------------------
DoCmd.SetWarnings False
'------------------------------------------------------------
' Run Query to clear out table
'------------------------------------------------------------
DoCmd.OpenQuery "qryClearEmpLog", acNormal, acEdit
DoCmd.OpenQuery "qryClrTimeLogOUTTable", acNormal, acEdit
DoCmd.OpenQuery "MakeTimeLogEmp", acNormal, acEdit
'------------------------------------------------------------
' Open TimeLOGIn Table
'------------------------------------------------------------
Set TimeLOGIn = New ADODB.Recordset
TimeLOGIn.Open "Timelogin", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'------------------------------------------------------------
' READ First Record of the TimeLOGIn Table
'------------------------------------------------------------
TimeLOGIn.MoveFirst
'------------------------------------------------------------
' READ TimeLOGIn Table is EOF
'------------------------------------------------------------
Do Until TimeLOGIn.EOF
'------------------------------------------------------------
' Open EmpFinalTimeLog Table
'------------------------------------------------------------
Set EmpFinalTimeLog = New ADODB.Recordset
EmpFinalTimeLog.Open "EmpFinalTimeLog", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
TimeLOGIn.MoveNext
'------------------------------------------------------------
' This will add a new record
'------------------------------------------------------------
EmpFinalTimeLog.AddNew
'------------------------------------------------------------
' If Timeout field is = to 12:00 AM
'------------------------------------------------------------
If TimeLOGIn.Fields("TimeOut"
'------------------------------------------------------------
' Move fields from Login record to fields in the Logout record
'------------------------------------------------------------
EmpFinalTimeLog.Fields("TimeStamp"
EmpFinalTimeLog.Fields("EmpNo"
EmpFinalTimeLog.Fields("Name"
EmpFinalTimeLog.Fields("TimeIn"
EmpFinalTimeLog.Fields("Date"
'------------------------------------------------------------
' Read next record in the TimeLOGIn Table
'------------------------------------------------------------
TimeLOGIn.MoveNext
'------------------------------------------------------------
' if TimeLOGIn is EOF then update EmpFinalTimeLog table and goto end of program
'------------------------------------------------------------
If TimeLOGIn.EOF Then
EmpFinalTimeLog.Update
GoTo 50
Else
End If
'------------------------------------------------------------
' If not EOF and TimeOut field in LOGIn record is not equal
' to 12:00 AM then update LOGOut field TimeOut with TimeOut
' field in the LOGIn record
' then update the LOGOut table
'------------------------------------------------------------
If TimeLOGIn.Fields("TimeOut"
EmpFinalTimeLog.Fields("TimeOut"
EmpFinalTimeLog.Update
End If
'------------------------------------------------------------
' Read next record in the TimeLOGIn Table
'------------------------------------------------------------
TimeLOGIn.MoveNext
If TimeLOGIn.EOF Then GoTo 50
End If
Loop
50
TimeLOGIn.Close
MsgBox ("File Has Been Updated"
End Sub
Private Sub OK_Click()
On Error GoTo Err_OK_Click
DoCmd.Close
Exit_OK_Click:
Exit Sub
Err_OK_Click:
MsgBox err.Description
Resume Exit_OK_Click
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This is ran from a button on a form, for now.
This sample is from the table it gets the info from:
TimeStamp EmpNo Name TimeIN TimeOut Date
2/3/2004 5:23:20 PM 1184 Tanya 5:30:00 AM 12:00:00 AM 2/3/2004
2/3/2004 5:23:23 PM 1184 Tanya 12:00:00 AM 5:45:00 PM 2/3/2004
2/3/2004 5:23:26 PM 1184 Tanya 6:30:00 PM 2:00:00 AM 2/3/2004
2/3/2004 5:23:29 PM 1184 Tanya 12:00:00 AM 6:45:00 PM 2/3/2004
2/3/2004 5:23:31 PM 1184 Tanya 8:30:00 PM 12:00:00 AM 2/3/2004
2/3/2004 5:23:33 PM 1184 Tanya 12:00:00 AM 10:30:00 PM 2/3/2004
2/4/2004 5:37:58 PM 1184 Tanya 5:30:00 PM 12:00:00 AM 02/4/2004
2/4/2004 5:41:49 PM 1184 Tanya 12:00:00 AM 5:45:00 PM 2/4/2004
2/4/2004 6:14:17 PM 1184 Tanya 6:15:00 PM 12:00:00 AM 2/4/2004
My results:
TimeStamp EmpNo Name TimeIN TimeOut Date
2/4/2004 5:37:58 PM 1184 Tanya 5:30:00 PM 10:30:00 PM 2/4/2004
2/3/2004 5:23:26 PM 1184 Tanya 6:30:00 PM 5:45:00 PM 2/3/2004
I'd appreciate any help!