This probably happens when the *main* form is at a new record. Since the
main form's primary key is then null, the foreign key field in the subform
will remain null.
To prevent this happening:
1. Open the subform's table in design view.
2. Select the foreign key field.
3. In the lower pane, set the Required property to Yes for this field.
That prevents the save, but the user does not get the message until they
finish entering the subform record and try to save it. To give them the
message earlier, cancel the BeforeInsert event of the subform if there is no
record in the main form. Example event procedure:
Private Sub Form_BeforeInse rt(Cancel As Integer)
If Me.Parent.NewRe cord Then
Cancel = True
MsgBox "Enter the main form record first."
End If
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<Th************ **@yahoo.com> wrote in message
news:11******** *************@v 46g2000cwv.goog legroups.com...
I am using an autonumber as a form id with a SubForms (which
automatically fill the linking fields from the parent into the child).
Occasionally (maybe 5% of the time) the autonumber does not work... it
simple continues to say "(autonumbe r)" and so the child linking field
isn't created. The data entered is in the table but the autonumber id
field is blank so the subform linked data can not be linked and/or
displayed. Anyone have any suggestions?