Never done anything like this so wild brainstorm.
Have one field for time: TheTime
Have only EmployeeID combobox and two buttons on form.
Should not have both StatusId and Status fields in tblClockInOut. Why does StatusID not show in datasheet?
With this code, form does not need RecordSource.
Code:
Private Sub SaveStamp(strStatus)
CurrentDb.Execute "INSERT INTO tblClockInOut(EmployeeID, Status, TheDate, TheTime) " & _
"VALUES(" & Me.cboEmployee & ", '" & strStatus & "', Date(), Time())"
End Sub
Private Sub cmdClockIn_Click()
Dim db As dao.Database
Dim rst As dao.Recordset
Set db = CurrentDb()
If Not IsNull(Me.cboEmployee) Then
Set rst = db.OpenRecordset("SELECT TOP 1 Status FROM tblClockInOut WHERE EmployeeID =" & Me.cboEmployee & " ORDER BY TheDate Desc, TheTime Desc;", dbOpenDynaset)
If Not rst.EOF Then
If rst!Status = "ClockIn" Then
MsgBox "Must click ClockOut"
Exit Sub
End If
Call SaveStamp("ClockIn")
MsgBox " signed in"
End If
Set rst = Nothing
Else
MsgBox "Must select employee ID"
End If
End Sub
Private Sub cmdClockOut_Click()
Dim db As dao.Database
Dim rst As dao.Recordset
Set db = CurrentDb()
If Not IsNull(Me.cboEmployee) Then
Set rst = db.OpenRecordset("SELECT TOP 1 Status FROM tblClockInOut WHERE EmployeeID =" & Me.cboEmployee & " ORDER BY TheDate Desc, TheTime Desc;", dbOpenDynaset)
If Not rst.EOF Then
If rst!Status = "ClockOut" Then
MsgBox "Must click ClockIn"
Exit Sub
End If
Call SaveStamp("ClockOut")
MsgBox " signed out"
End If
Set rst = Nothing
Else
MsgBox "Must select employee ID"
End If
End Sub