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 Issue

Status
Not open for further replies.

tekyge

Programmer
Dec 11, 2005
125
US
Below is the code I have that adds a new record each time an employee logs out or in. What I am tring to do is rather than it adding a new record I want it to edit the time record of the employee clocking in or out. I am having a problem figureing out how to find and edit the record I need with the code below. I know the Set rst should open the table find the record the ssn they enter and edit it. ANy help


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

Set rst = CurrentDb.OpenRecordset("Time", dbOpenDynaset)

rst.AddNew
rst![SSN].Value = Me.SSN 'use the name of the field for your date in your table
rst![Name].Value = DLookup("[Name]", "Employees", "[SSN]='" & Me.[SSN] & "'")
rst![Time].Value = Now()
rst.Update
rst.Close
'--
DoCmd.Close
Else
MsgBox "No Employee On File"
Me.SSN.SetFocus
End
End If
End Sub
 
Never got it!!!!


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

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

rst.Edit
rst![SSN].Value = Me.SSN 'use the name of the field for your date in your table
rst![Name].Value = DLookup("[Name]", "Employees", "[SSN]='" & Me.[SSN] & "'")
rst![Time].Value = Now()
rst.Update
rst.Close
'--
DoCmd.Close
Else
MsgBox "No Employee On File"
Me.SSN.SetFocus
End
End If
End Sub
 
I ment nevermind I got it Sorry.

But I do have another problem I started another form for this issue but maybe you can help:

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
 
I'm assuming that you've already Dimmed your recordset variable?
 
The code is work all but the code below. I need to use data manipulation but I can figure out how to turn the below code into that?

rst![TotalTime].Value = 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