Closing a form only if value is selected.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have tried this under BeforeUpdate() and the following and I can't get it
to cancel the event. I am trying to make the form give an error message if
no name is selected from the list. Right now, if the EmlpoyeeID field is
left blank the form closes and updates the record. What am I doing wrong?
----------start code---------------
Private Sub btnOkay_Click()
On Error GoTo Err_btnOkay_Click

If IsNull(Me!EmployeeID) Then
MsgBox "You must select an employee from the list"
Me!lblEmployee.ForeColor = 255
Me!EmployeeID.SetFocus
Exit Sub
Else
Me!lblEmployee.ForeColor = 0
DoCmd.Close
End If


Exit_btnOkay_Click:
Exit Sub

Err_btnOkay_Click:
MsgBox Err.Description
Resume Exit_btnOkay_Click

End Sub
-------------end code----------------
 
Hi,
Is your EmployeeID a String Value? To make sure that you catch all types of
emptyness change the test to :-
If IsNull(Me.EmployeeID) Or Me.EmployeeID = "" Then
 
Back
Top