form/subform-require at least 1 new subform record at data entry

J

jyow32

I have a main form (for parent table data entry) with a subform (for child
table data entry). The parent/child table relationship is one-to-many. How
can you set up the subform to require that data for at least one new record
be entered(for insertion into the child table) when data is entered into the
main form (for insertion into the parent table)?

Also, can you use data entered into the main form to propogate fields in the
subform?
 
A

Allen Browne

jyow32 said:
I have a main form (for parent table data entry) with a subform (for child
table data entry). The parent/child table relationship is one-to-many.
How
can you set up the subform to require that data for at least one new
record
be entered(for insertion into the child table) when data is entered into
the
main form (for insertion into the parent table)?

Also, can you use data entered into the main form to propogate fields in
the
subform?

You cannot create a *related* record in the child table until you have saved
the main record in the primary record. Therefore you cannot require the
existence of a related record as a condition for accepting the new main
record. Typical chicken'n'egg problem.

One workaround is to use the AfterInsert event procedure of the main form to
execute an Append query statement or AddNew to the RecordsetClone of the
subform. This gives a related record, but its content is probably
meaningless.

Alternatively, you could add new records to temporary tables (a primary and
a related one), and only add them to the real tables when you know that both
records exist. In practice, this is something of a nightmare in a multiuser
scenario, e.g. by the time you go to write to the real table, you could have
data that violates rules (e.g. duplicates.)

In any case, you would also need to consider what happens if the user
deletes related records (which now violates your business rule that there
must be at least one related records.)

You might want to reconsider why this business rule is important, and
whether trying enforce a rule that any primary record has related records is
actually going to make any real difference to the integrity of the data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top