Form and Subform Events

G

Guest

I have a form and subform. The form has timesheet details such as name, week
ending and total time for this timesheet which is calculated from the
individual entries in the subform. This is the timesheet header record.
The subform is a datasheet where times are entered - one row for each entry.
These are the timesheet detail records.
If a person creates a new timesheet (header record), and then does not enter
any times in the subform (no detail records) before closing the timesheet, I
want to delete the blank timesheet header record.
I thought if I refresh the main form, and check if the total hours are zero
(there are no detail records), I would have a condition which would allow me
to decide to delete the timesheet header record. Unfortunately I cannot work
out which event to use.
Lostfocus happens when I move from the main form to the subform so that
cannot be used. I could be moving to the subform to creae the detail
records. On close happens when I close the form so I could have created a
header, and moved to another existing header record. Any suggestions as to
how this could be done, or if there is another way?
 
A

Allen Browne

Use the Unload event of the form, to execute a Delete query that kills any
records that have no related record.

The Unmatched Query wizard (when you create a new query) will help you
identify the timesheet header records that have no child records.

The Unload event can be cancelled if you want to write the code to give the
user the option not to close the form. If you want to wrap the action query
in a transaction, rollback, and cancel the form close, this article provides
an example of reliable transaction code:
http://allenbrowne.com/ser-37.html
 
G

Guest

Thanks Allen. that fixed my problem. Created an unmatched query and run a
delete query based on the unmatched query when Unload runs
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryTimeCardDelete", acViewNormal
The only extra thing I had to do was kill off the warning message.
Thanks again.
 

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