Hi Experts, good day!
I have hard time coding the click event when I click cmdTime on the second time a message box will say, "Your first time in for 2/16/13 at 9:00:33 am, Are you sure you want to record this time in, Yes Cancel?" The time 1:22:33 is the first time in from database. Then the form will unload if yes is click.
Also, when the employee has no time out for the first time in or second time in yesterday because he/she forgot it, when he click timein for current day, a messagebox will say, "You have no (either first or second) time out for 2/17/13. Please input your time out ________(hh:mm:ss). Are you sure you want to record this time out? if yes, the inputted time will record to database. and unload the form.
Help me pls. experts. Thank you very much. below is code.
Private Sub cmdEnter_Click()
Dim sTrID As String
sTrID = txtEmployee_IdNo.Text
Set rs = New ADODB.Recordset
rs.Open "Select * from Employees where Employees_IdNo like '" & sTrID & "'", cn, adOpenKeyset, adLockPessimistic
lblEmployee_Name.Caption = vbNullString
If Not rs.EOF Then
lblEmployee_Name.Caption = rs!Lastname
Ado.RecordSource = "Select * from Employees where Employees_IdNo Like '" & sTrID & "'"
Ado.Refresh
While (rs.EOF = False)
lblEmployee_Name.Caption = rs.Fields(1) & Space(2) & rs.Fields(2) & Space(2) & rs.Fields(3)
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
lblEmployee_Name.Enabled = True
lblHi.Visible = True
cmdTimeIn.Enabled = True
cmdTimeOut.Enabled = False
Else
MsgBox "No records found! ", vbExclamation, "Time In & Time Out"
txtEmployee_IdNo.Text = ""
txtEmployee_IdNo.SetFocus
End If
End Sub
Private Sub cmdTimeIn_Click()
Set rs = New ADODB.Recordset
rs.Open "select*from Time_In", cn, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!Employees_IdNo = txtEmployee_IdNo.Text
rs!Time_In = Format(Now, "hh:mm:ss")
rs!Date_In = Format(Date, "mm/dd/yy")
rs.Update
rs.Close
MsgBox "Your Time In has been recorded! Please come back for your Time Out.", vbInformation, "Time In / Time Out"
Set rs = Nothing
cmdTimeOut.Enabled = True
Exit Sub
End Sub
Private Sub cmdTimeOut_Click()
Set rs = New ADODB.Recordset
rs.Open "select*from Time_Out", cn, adOpenKeyset, adLockOptimistic
rs.AddNew
rs!Employees_IdNo = txtEmployee_IdNo.Text
rs!Time_Out = Format(Now, "hh:mm:ss")
rs!Date_Out = Format(Date, "mm/dd/yy")
rs.Update
rs.Close
MsgBox "Your Time Out has been recorded!", vbInformation, "Time In / Time Out"
Set rs = Nothing
Exit Sub
End Sub
Private Sub Form_Load()
lblEmployee_Name.Enabled = False
lblHi.Visible = False
cmdTimeIn.Enabled = False
cmdTimeOut.Enabled = False
End Sub
Kimangel