beforeupdate

G

Guest

I have a mainform and subform. What code do I put in the beforeupdate event
of the main form if I dont want it to add a record or close until the user
has entered a value in a text box (datasheet) of the subform.

Cheers,

nB
 
A

Allen Browne

Normally the main form is bound to a primary table, and the subform to a
related table.

If so, it is logically impossible to create a record in the secondary table
that is related to a record in the main table that does not exist yet.

If follows that you cannot use the BeforeUpdate event of the main form to
block the entry until after you have created the subform record.
 
G

Guest

Hi Allen,

What I meant was I want the user to also add a record in the subform before
closing the main form. I dont want the user adding a record in the main
form without also adding a record in the subform.

nB
 
A

Allen Browne

The point is that you cannot require this.

What happens if the user moves to another record in the main form, or
perhaps to the new record? Are you still going to require that they enter a
record in the subform while the main form at a new record before they can
close the main form?

I can understand *why* you want to do that: to avoid parent records that
have no children. But the logic to do that doesn't work.

You could run a query in the Unload event of the main form, to identify any
main-table records that have no chilren. But that could occur because the
child records have been deleted, or they might be records from a previous
session. And what will you do if you find them? If you just prevent the user
from closing the form, you will have users who use Ctrl+Alt+Del to kill
Access, and you will end up with a corrupted database.

So, although your goal is understandable, there is not a simple, quick,
practical solution to this issue.
 
G

Guest

Thanks - that makes sense. I will put a pop up msg box before update on the
main record advising the user to enter data into the subform.

nB
 

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