How to avoid the Parent ID not found Error?

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 14:43
Joined
Mar 22, 2009
Messages
1,037
How to avoid/restrict users to not enter sub-form records before the Autonum(Primary Key) on the Parent Form generated?
 
Access will give an error if/when you attempt to add a record on the Many side of a relationship before there is a valid entry on the 1 side. eg You must have a parent before adding related child.
Doesn't have to be an autonumber, but it must be PK.
 
At the first point that you know you are going to enter records in the sub-form you must create the entry for the parent form. There is more to this comment than you might first realize, though. The trick is knowing that you are going to enter those records. SO... one possible suggestion is to not show the sub-form if on a new parent record, at least until the user does something to the parent that triggers creation of the record. Exactly how you approach this is up to you, but just remember... don't GIVE a user the chance to screw up by showing something that isn't ready for use.
 
or you can use the Current Event of the main form, to dis Allow Addition to the subform:

private sub form_current()
Me!subformname.Form.AllowAdditions = (Nz(Me!ID, 0) <> 0)
end sub

private sub form_afterupdate()
call form_current
end sub
 

Users who are viewing this thread

Back
Top Bottom