Re: Delete event not followed up with BeforeDelConfirm or AfterDel
- From: Marty <Marty@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 3 Aug 2006 09:51:01 -0700
Howdy Allen,
Here is how the story plays out. I'm afraid that I painted an
over-simplified picture in my description of the problem. In addition to
having a form and subform to show data from a table and a related table, I'm
trying to wrap all changes to the data in a Transaction. I'm new to this,
and am following the guidelines set out in the Access 2002 Developer's
Handbook (by Getz et al). Whenever the Form_Current event fires, I have it
call ResetData to perform the following steps: (1) commit any transaction
that may be running, (2) run queries to re-populate the form - these queries
run under the workspace that will also contain the transaction and (3) begin
a new transaction.
This poses several challenges to the series of events that normally
follows a Delete. First, repopulating the form will, (even in the absence of
a transaction) terminate the event series. Second, if the program is changed
to avoid re-populating the form, adding a transaction will cause all records
deleted from the related table to be captured as part of the transaction.
You must add logic to the event series to commit the transaction. However,
this must not happen in the Delete event, as that will (for reasons I don't
understand) also terminate the event series. It works if you run the Commit
in the AfterDelConfirm, however. My form appears to be functioning with the
following outline:
Form_Delete
- set up a flag to prevent the Current event from calling ResetData
Form_Current
- call ResetData only if a delete is not in progress
Form_BeforeDelConfirm
- check to see if there are any related records, if not then just use
standard Access delete logic (Cancel = False, exit sub)
- If there are related records:
- - confirm with the user that all records should be deleted
- - if not, set Cancel = True and exit
- - if so
- - - move through recordset deleting records,
- - - Cancel = False
- - - Response = acDataErrContinue (suppresses normal confirmation msg)
Form_AfterDelConfirm
If a transaction is running, commit it.
For what it is worth, I am entertaining the suspicion that running the
Debugger complicates things even further. I have had the event series fail
while running the debugger. Then, after restoring the data and adding your
logging logic, the same series works fine. Hmm. This is not very
convincing, I admit. But your logging suggestion has made it possible to
finish the job. Thank you very much
Marty
"Allen Browne" wrote:
If all the Confirm boxes are checked, and we are talking about JET tables in.
an MDB database (not an ADP proejct), you should see the BeforeDelConfirm
event after the Delete event.
Is it possible the event is firing, but doing nothing? Try adding this as
the first line in BeforeDelConfirm:
Debug.Print "Form_BeforeDelConfirm at " & Now()
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Marty" <Marty@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5E916CBA-1D5D-44B2-9BB4-97D457065C66@xxxxxxxxxxxxxxxx
Howdy All,
I'm setting up a form/subform combination where each of the two forms
shows data from two related tables. The problem arises when I select a
record on the Main form and press the Delete key; the logic for the Main
form
sees a "Delete" event and then a "Current" event, and then stops! I had
been
expecting a BeforeDelConfirm event and an AfterDelConfirm event to fire.
I
was going to use the "BeforeDelConfirm" event to remove the related
records
shown in the subform.
The option "Confirm Record Changes" is set to true (that is, it is
checked). I do see the proper set of events when I try to delete a single
record on a simple form (that is, with no nested subform). It "feels"
like a
problem with the nested forms, but I can't pin down the problem.
Any ideas?
Thank you
Marty
- Follow-Ups:
- Re: Delete event not followed up with BeforeDelConfirm or AfterDel
- From: Allen Browne
- Re: Delete event not followed up with BeforeDelConfirm or AfterDel
- References:
- Re: Delete event not followed up with BeforeDelConfirm or AfterDelConf
- From: Allen Browne
- Re: Delete event not followed up with BeforeDelConfirm or AfterDelConf
- Prev by Date: Re: How to set security on forms so that data cannot be deleted?
- Next by Date: RE: multiple selections in form
- Previous by thread: Re: Delete event not followed up with BeforeDelConfirm or AfterDelConf
- Next by thread: Re: Delete event not followed up with BeforeDelConfirm or AfterDel
- Index(es):