Form_AfterUpdate does not fire on Form_Delete operations

stevemanser

Registered User.
Local time
Today, 19:06
Joined
Oct 28, 2008
Messages
18
On my form I have an AfterUpdate event that updates some grand totals, but it doesn't fire when a record is DELETED. I have tried putting the UpdateTotals code in the Form_Delete event, but it runs too early (i.e. before the actual delete) so the values are still the original ones, and thus wrong.

Any ideas on getting the grand totals calculated correctly after a delete?

NOT WORKING FOR DELETES:

Private Sub Form_AfterUpdate()
Call UpdateTotals(Me.Parent.Form, txtOrdGID)
End Sub

OR


Private Sub Form_Delete(Cancel As Integer)
Call UpdateTotals(Me.Parent.Form, txtOrdGID) <--- fires too early
End Sub

Steve
 
After Update does not fire when code does things to the form. You need to call it explicitly if you want it to fire. So, in the code where you have caused something to change, you would call the After Update event by using:

Call Form_AfterUpdate()

or

Call Me.AfterUpdate

if called from the same form's code and if you need to from another form or module then you have to change it to Public from Private and then use:

Call Forms!FormName.AfterUpdate
 
Ok, I have tried calling Form_AfterUpdate or UpdateTotals directly from the Form_Delete event, which fires when a user deletes a record, and the routines DO actually fire, but they fire too early. I need something that fires automatically AFTER the delete record.

Anyway, after several hours of playing about I have come up with this:

1. Disallow traditional deletes:

Private Sub Form_Load()
Me.AllowDeletions = False
End Sub

2. Then, create a button in the subform called cmdDelete, with this event:

Private Sub cmdDelete_Click()
Me.AllowDeletions = True
DoCmd.RunCommand acCmdDeleteRecord
Me.AllowDeletions = False
Call UpdateTotals(Me.Parent.Form, Me.Parent.txtOrderID)
End Sub

This is the only way I have found that will delete the record and THEN fire the UpdateTotals code. Apparently, you could use the Form_AfterDelConfirm event, but this relies on having confirmations on, which is a user setting, so could be turned off in some systems.
 

Users who are viewing this thread

Back
Top Bottom