Force entry in subform?

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

Hi!

I have a mainform with a subform. When I create a new record in the mainform
I would like to force the user to create at least one new record in the
subform as well, ie the user should't be able to creat a new record in the
mainform with an "empty" subform.

How can I do this?

Any input appreciated.

/e
 
Eric, this is a chicken'n'egg problem.

You cannot create a related record in the subform until you have the primary
record in the main form. Therefore, having a child record cannot be a
condition for permitting the main record to be created.

If it is absolutely essential to enforce your rule, create a temporary table
to hold the new main form record, and another temp table for the subform
records. Bind your data entry form to the temp tables. Add a "Commit"
button, which executes a pair of Append query statements to copy the data
from the temp tables to the real tables, and deletes them from the temp
tables. Then execute a pair of Delete query statements to empty the temp
tables. The code that executes these 4 action queries can check for child
records before execution: using a query statement like one from the
Unmatched Query wizard. The 4 action queries should probably be executed in
a transaction to get an all-or-nothing result. For help on transactions,
see:
http://allenbrowne.com/ser-37.html

In general, the gain does not justify the trouble and clumsiness of the
above. If it is justified, you may also need to consider what happens when
the user deletes child records (does it leave none?) or possibly reassigns
child records to another parent.
 
Allen, thanks for your answer.

You don't think it can be done with some sort of afterupdate-event-code in
the mainform (ie, "when you have created a record in the mainform,
automatically create a new record in the subform and force the the user to
fill in data").

What I would like to do is to create a mainform with projects and in the
subform I want to allocate consultants to the project. I don't want it to be
possible to create a project in the mainform without booking up at least one
consultant in the subform (there can be more than one consultant allocated
to a project).

Maybe you have a better way to solve it?

Regards,

/je
 
Yes, it would be possible to use the AfterInsert event procedure of the main
form to AddNew to the RecordsetClone of the subform (or else to Execute an
append query statement directly on the subform's table.)

That assumes that you know what data you want automatically entered for the
subform, or course.
 
thanks! I'll try it out!

/e


Allen Browne said:
Yes, it would be possible to use the AfterInsert event procedure of the main
form to AddNew to the RecordsetClone of the subform (or else to Execute an
append query statement directly on the subform's table.)

That assumes that you know what data you want automatically entered for the
subform, or course.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

to
 
Back
Top