Need help with a required field error on a form

A

Amit

MS Access, Windows XP
==================
Hi,

I am getting an error message "The field tblContact.ContactID cannot contain
a null value because the Required property for this field is set to True.
Enter a value in this field." when I open a form to add a new record.

The ContactID is the Autonumber Primary key in the table, and a query (with
all the fields) is the Control Source for this form.

I'm opening this form from another form using a button.

I've been racking my brain, and have done some testing, but I've been unable
to figure out a solution to this bug. Will appreciate any help.

Here is the relevant code for the form events - Current and Load:
(I do have code in FormUnload, but I don't think that is relevant to this
error)
=======================================================

Private Sub Form_Current()
If Me.NewRecord Then
Me.ProgramID =
[Forms]![frmMenu_Communication]![txtProgramID_Communication]
'code to add CurrentUser to the record
If Not IsNull(CurrentUser()) Then
Me.ContactRecordCreateUser = CurrentUser()
End If
End If
End Sub

=======================================================
Private Sub Form_Load()
If (OpenArgs <> "") Then
Me.ProgramID = OpenArgs
End If
End Sub
======================================================

The weird thing is that I have another form with same logic and similar code
and I do not get any error message for that.

I tested the events of the code and here is the sequence:
1. FormOpen (ContactID is null)
2. FormLoad (null)
3. FormCurrent (null)
4. BeforeInsert (null)
5. OnDirty (null)
6. Error message displayed - twice
7. BeforeUpdate (ContactID has a value now)
8. AfterUpdate (has a value)
9. Error message displayed again when I close the form

I also tried another thing - I added a control for ContactID on my form and
when I open the form to add a new Contact, the form opens and I can see that
the textbox for ControlID has a value displayed, and before I can add some
data, I get the error message window.

Will appreciate some help with this.

Thanks.

-Amit
 
A

Amit

Never mind. I figured it out.

There is a sub-form on the form I'm opening, and code in that sub-form was
causing the error message.

-Amit
 
Top