Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Clock Help

Status
Not open for further replies.

tekyge

Programmer
Dec 11, 2005
125
US
I am building a time clock system where the employee can type there ssn and clock in or out using only one button. Ok everything is working except that I want to have the code below give me a updated total in hours and minutes of the total time an employee has worked but nothing is showing in the TotalTime table after I clock in. Any help.

Private Sub clock_Click()
If Me.SSN = DLookup("[SSN]", "Employees") Then
'--

Set rst = CurrentDb.OpenRecordset("SELECT * FROM [Employees] Where [Employees].[SSN]='" & Me.[SSN] & "'")

rst.Edit
rst![TotalTime].Value = rst![TotalTime].Value + rst![Time].Value - Now()
rst![Time].Value = Now()
rst.Update
rst.Close
'--
DoCmd.Close
Else
MsgBox "No Employee On File"
Me.SSN.SetFocus
End
End If
End Sub
 
Where is the code that updates TotalTime table? If you meant the TotalTime field on the Employees table, I think you need to uase DateDiff/DateAdd when doing the time calculation instead of arithmetic operators?.....

I have great faith in fools; self-confidence my friends call it.
-Poe
 
This would be the code used when the table is opened and edited:

rst![TotalTime].Value = rst![TotalTime].Value + rst![Time].Value - Now()
 
OK but still think you need to use date manipulation functions, and not "+"......

I have great faith in fools; self-confidence my friends call it.
-Poe
 
I know I should use data manupulation but how do I turn that code into what I need?
 
Here is what I have so far but it is not working? It gives no error but there is no data in the TotalTime field

rst![TotalTime].Value = DateDiff("n", rst![TotalTime].Value + rst![Time].Value, Now())
 
Got it Thanks guys and the code below is the results:

If Me.SSN = DLookup("[SSN]", "Employees", "[SSN]='" & Me.[SSN] & "'") Then
'--

Set rst = CurrentDb.OpenRecordset("SELECT * FROM [Employees] Where [Employees].[SSN]='" & Me.[SSN] & "'")
If rst![ClockInOut].Value = True Then
rst.Edit
rst![TotalTime].Value = rst![TotalTime].Value + DateDiff("n", rst![Time].Value, Time())
rst![Time].Value = Time()
rst![ClockInOut].Value = Unchecked
rst.Update
rst.Close
Else
rst.Edit
rst![Time].Value = Time()
rst![ClockInOut].Value = Checked
rst.Update
rst.Close
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top