Form error

gsrajan

Registered User.
Local time
Today, 13:05
Joined
Apr 22, 2014
Messages
227
If the user click on any of the field and close the form without entering data, user get the error message "You must enter a value in the Masterdata.EmployeeID field ( which is primary key ). Please let me know how to handle this error.

Thank you.
 
Well you haven't given us much to go on, but it sounds to me as though you have some code that is setting a value in one of the controls which is making the form "Dirty". When you try to close the form Access tries to save the record but can't because it needs a value for the Primary Key.
 
Yes, you are correct. I need to empty the form before closing. I have given a command button to undo it and then close the form. I have to accomplish this without the undo record button.

Thank you.
 
Yes, you are correct. I need to empty the form before closing. I have given a command button to undo it and then close the form. I have to accomplish this without the undo record button.

Thank you.
Then you will have to either remove the code that makes the form dirty or catch the error in some error handling code and undirty the form there. Only other way, that's just come to mind, is to use some validation code in the form's Before Update event to check for a Null Primary Key and undirty the form then.
 
If you use the following code it should allow you to close the form without the error message.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  If IsNull(Me.EmployeeID) Then
    Me.Undo
  End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom