Alright, i've been driving myself mad for a day or two now trying to get this functionality working.
So basically i'm building a database with multiple users to 'check in' and 'check out' multiple times per day (hoping 2 check in and 2 check out inc lunch). I have two tables linked, and originally I had this system partially working:
Code:
Private Sub btnCheckin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblEmployees", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtUserName & "'"
If rs.NoMatch = True Then
Me.lblWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False
Dim CountTime As Long
CountTime = DCount("User", "qry_ClockIn_CheckSYSIn_1")
Dim CountTime2 As Long
CountTime2 = DCount("User", "qry_ClockIn_CheckSYSIn_2")
If (CountTime > 0) Then
MsgBox "You need to complete previous Clock Out", vbOKOnly
ElseIf (CountTime2 > 0) Then
MsgBox "You need to complete previous Clock Out", vbOKOnly
ElseIf IsNull(Me.txtUserName) = True Then
MsgBox "Scan Employee Barcode!", vbOKOnly
Me.lblWrongUser.Visible = True
Else
Me.frmLogin_SUB.SetFocus
DoCmd.GoToRecord , , acNewRec
Me.frmLogin_SUB!User = Me.txtUserName
Me.frmLogin_SUB!CheckIN = Now
Me.frmLogin_SUB!Day = Date
MsgBox "You have successfully clocked in at " & Now(), vbOKOnly
RunCommand acCmdSaveRecord
Me.frmLogin_SUB.Form.Refresh
DoCmd.GoToRecord , , acLast
Me.Refresh
End If
End Sub
And for Checking out
Code:
Private Sub btnCheckOut_Click()
Dim CountTime3 As Long
CountTime3 = DCount("User", "qry_ClockIn_CheckSYSOUT")
If IsNull(Me.txtUserName) = True Then
MsgBox "Scan Employee Barcode!", vbOKOnly
ElseIf (CountTime3 = 0) Then
MsgBox "You have no open Clock In records. Please return to Clock In.", vbOKOnly
Else
If Me.Dirty Then Me.Dirty = False
Me.Requery
Me.txtCheckOUT = Now()
MsgBox "You have successfully clocked out at " & Now(), vbOKOnly
Forms!frmLogin.frmLogin_SUB.SetFocus
DoCmd.GoToRecord , "User", acGoTo
Forms!frmLogin.frmLogin_SUB.Requery
Forms!frmLogin.frmLogin_SUB.Form.Refresh
End If
End Sub
It partially works, however constantly creates new records, and I can't get it to work properly.
The Query(s) consists of:
qry_ClockIn_CheckSysIN_1
Time ID |
|
Employee |
[Forms]![frmLogin]![txtUserName] |
TimeIN |
Is Not Null |
TimeOUT |
Is Null |
qry_ClockIn_CheckSysIN_2
Time ID |
|
Employee |
[Forms]![frmLogin]![txtUserName] |
TimeIN |
|
TimeOUT |
Is Null |
qry_ClockIn_CheckSYSOUT
Time ID |
|
Employee |
[Forms]![frmLogin]![txtUserName] |
TimeIN |
Is Not Null |
TimeOUT |
Is Null |
Hope that's enough information to help, and thanks for response in advance!
even if there is something more simple or easier, as the code can be changed, it only needs to support multiple users that are checked by the rs function
Cheers!