cannot contain null value - Required property is true

  • Thread starter Thread starter M Skabialka
  • Start date Start date
M

M Skabialka

I created a form eons ago which gives the user several combos to select
from. This creates a form filled with data which is then printed off one
time for signature. Now the users want a historical record of the
selections they made, including the data as it was at that time (like the
old phone number, address, work schedule, etc).

So I created a table with all the info they want to keep and bound the form
to it. Adding records is easy, I have marked anything saved as "locked" so
they can't change it, but I have a problem with the form:

When the user creates a new record, then tries to back off and go to the
previous record, he gets a message "The field 'mytable.employeeID' cannot
contain a null value because the Required property for this field is set to
true. Enter a value in this field." The Navigations buttons are set to not
allow new records. The button to create new records initializes some fields
but not EmployeeID. When the message is up CTRL Break does not go to a code
module, the message goes away.

I can't figure out where exactly this message is triggered so that I can do
something about it like disable the message since the record is blank
anyway, or undo the new record, or add something to the field then delete
the record. I am unable to capture the error message on any of these
events:
Open Load Resize Activate Current

Can anyone help me here?
Thanks,
Mich
 
This error occurs when the form tries to save the record when the user moves
away from it. It's caused by a field in the table that has its Required
property set to Yes.

Either change that property in the table, or you can use the Form's
BeforeUpdate event to trap this error and then to Undo the addition of the
new record by canceling the BeforeUpdate event.
 
Either change that property in the table, or you can use the Form's
BeforeUpdate event to trap this error and then to Undo the addition of the
new record by canceling the BeforeUpdate event.

I am not sure how to do this.

I tried this to see if this is where the event occurs but there is no error
at this point.

Private Sub Form_BeforeUpdate(Cancel As Integer)
MsgBox Err.Number & " " & Err.Description
End Sub

and the message occurs after this.
 
Sorry. ..

You're correct, the error occurs after the end of the BeforeUpdate event.
You should be able to trap this error in the form's Error event.

However, may I recommend that you put code in the form's BeforeUpdate event
that knows which data need to be validated, and do that validation yourself,
thereby not relying on the form to error itself?

You will be better served to address the cause of the error, rather than
treating the error after it occurs.
--

Ken Snell
<MS ACCESS MVP>
 
Back
Top