form / subform

  • Thread starter Thread starter Eddy Maas
  • Start date Start date
E

Eddy Maas

Hi,

I've created a form and subform. The recordnr (autonr) is
the relation to both tables. This works quiet well exept
when user with her mouse first point to the subform fills
in the details and the fills in de mainform. My relation
is gone between the tables.

Can anyone advise me how to proceed ?

thanks a lot,

Eddy Maas
 
Presumably you have already created a relationship between the two tables
(Tools | Relationships), and checked the box for Referential Integrity.

That's the first step, but it will not prevent nulls in the foreign key
field. Open your subform table in design view. Choose the foreign key field.
In the lower pane of table design, set the Required property to Yes.

That will prevent the user from saving a record in the subform when there is
no record in the main form. Trouble is that they don't get the message until
they have filled in all the data. To give them the message at the beginning
of the process, cancel the BeforeInsert event of the subform:

Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Enter a main form record first."
End If
End Sub
 
Back
Top