Hi all,
I have a form with a checkbox showing whether an employee is currently active or away on leave. If they try to mark the employee active and there is leave, they get a message box telling them to edit the leave. It then cancels their change. When I change records, it tries to update the record, even though there is no update. This causes a few errors down the road if they try to go edit the leave period. Here's the code:
Code:
Private Sub chkActive_BeforeUpdate(Cancel As Integer)
If chkActive = -1 Then
If DCount("ID", "tblAbsence", "EmpNo= " & Me.EmpNo & " AND Description = ""Away"" AND Format(ExpectedDateAway,""Short Date"") <= Format(Now(),""Short Date"") AND Format(ExpectedDateBack, ""Short Date"") >= Format(Now(),""Short Date"")") <> 0 Then
'LEAVE DURING THIS PERIOD EXISTS
MsgBox "This employee is currently inactive due to leave. Please edit their leave to return to active status.", vbCritical, "Employee is on Leave"
Cancel = True
Me.chkActive.Undo
Exit Sub
End If
End If
End Sub
Thanks,
Scott