MS_Access_Amature
Registered User.
- Local time
- , 17:11
- Joined
- Nov 10, 2010
- Messages
- 56
This is my function:
Function PunchInOrOut(sMyCallingForm As String, MyPunchInOrOut As String, MyUserCodeAs String, MyUsername As String, MyPunchDate As Date, MyPunchTime As Date, ForFutureUse1$, ForFutureUse2$, ForFutureUse3$)
On Error GoTo MyErrorControl
Dim DB As DAO.Database, MyPunchID As Long
Set DB = CurrentDb
Function PunchInOrOut(sMyCallingForm As String, MyPunchInOrOut As String, MyUserCodeAs String, MyUsername As String, MyPunchDate As Date, MyPunchTime As Date, ForFutureUse1$, ForFutureUse2$, ForFutureUse3$)
On Error GoTo MyErrorControl
Dim DB As DAO.Database, MyPunchID As Long
Set DB = CurrentDb
Select Case MyPunchInOrOut
Case "IN"
' Does a punch OUT exist for current user and current date
MyPunchID = Nz(DLookup("[PunchID]", "Punches", "
Case "IN"
' Does a punch OUT exist for current user and current date
MyPunchID = Nz(DLookup("[PunchID]", "Punches", "
Code:
= '" & MyUserCode & "' AND [DateofWork] = #" & MyPunchDate & "# AND IsNull([TimeIn]) = True"), 0)
[COLOR=seagreen]' A punch OUT record exist, then update the record[/COLOR]
[COLOR=navy]If[/COLOR] MyPunchID > 0 [COLOR=navy]Then[/COLOR]
[INDENT]DB.Execute "UPDATE Punches SET [TimeIn] = #" & MyPunchTime & "# WHERE [PunchID] = " & MyPunchID
[/INDENT][COLOR=navy]Else[/COLOR]
[INDENT]DB.Execute "INSERT INTO Punches ([code], [DateOfWork], [TimeIn]) VALUES ('" & MyUserCode & "', #" & MyPunchDate & "#, #" & MyPunchTime & "# )"
[/INDENT][COLOR=navy]End If[/COLOR]
Forms(sMyCallingForm).ShortLog = "Last Punch IN: " & UCase(MyUsername) & " on " & MyPunchDate & " " & MyPunchTime
[/INDENT][COLOR=navy]Case[/COLOR] "OUT"
[/INDENT][INDENT][INDENT][COLOR=seagreen]' Does a punch IN exist for current user and current date[/COLOR]
MyPunchID = Nz(DLookup("[PunchID]", "Punches", "[code] = '" & MyUserCode & "' AND [DateofWork] = #" & MyPunchDate & "# AND IsNull([TimeOut]) = True"), 0)
[COLOR=navy]If[/COLOR] MyPunchID > 0 [COLOR=navy]Then[/COLOR]
[/INDENT][/INDENT][INDENT][INDENT][COLOR=seagreen]' Yes - then update the existing punch in with this punch out[/COLOR]
DB.Execute "UPDATE Punches SET TimeOut = Now() WHERE [PunchID] = " & MyPunchID
[/INDENT][COLOR=navy]Else[/COLOR]
[/INDENT][INDENT][INDENT][COLOR=seagreen]' No - then create a new record without a punch in[/COLOR]
DB.Execute "INSERT INTO Punches (Code, DateOfWork, TimeOUT) VALUES ('" & MyUserCode & "',#" & MyPunchDate & "#,#" & MyPunchTime & "# )"
[/INDENT][COLOR=navy]End If[/COLOR]
Forms(sMyCallingForm).ShortLog = "Last Punch OUT: " & UCase(MyUsername) & " on " & MyPunchTime & " " & Now()
[/INDENT]
[COLOR=navy]Case Else[/COLOR]
[INDENT]MsgBox "Sorry, option not implemented: " & MyPunchInOrOut
[/INDENT][COLOR=navy]End Select[/COLOR]
[COLOR=navy]Set[/COLOR] DB = [COLOR=navy]Nothing[/COLOR]
[COLOR=navy]Exit Function[/COLOR]
MyErrorControl:
DoCmd.SetWarnings [COLOR=navy]True[/COLOR]
[COLOR=navy]Select Case[/COLOR] Err.Number
[COLOR=darkslateblue]Case[/COLOR] 0
[COLOR=navy]Resume Next[/COLOR]
[COLOR=darkslateblue]Case[/COLOR] 52 [COLOR=seagreen]'cannot find a file[/COLOR]
[COLOR=navy]Resume Next[/COLOR]
[COLOR=navy]Case Else[/COLOR]
MsgBox "Error number " & Err.Number & ": " & Err.Description
[COLOR=navy]Resume Next[/COLOR]
[COLOR=navy]Exit Function[/COLOR]
[COLOR=navy]End Select[/COLOR]
[COLOR=navy]End Function[/COLOR]
I want to add to it for when people forget to punch in/out. For example: Say John punches in. He leaves the day and forgot to punch out. The next day he comes in and punches in again. The program is allowing this. I want it to be able to prevent punching in twice without punching out. And your can't punch out unless in your last record you punched out. So if John comes in the next day and punches in i want the program to automatically punch him out and put in 0:00 for yesterdays punch out so he could punch in for today. How can i go about this??