Solved Update main form total after subform record is deleted

Mike Krailo

Well-known member
Local time
Today, 13:07
Joined
Mar 28, 2020
Messages
1,694
Updating the main form total works great using an after update event for adding new items in the subform but does no good when a record is deleted. The On Delete event doesn't work because, the totals have not updated yet (it seems to only fire pre delete). The After Delete Confirmation event only works if confirmations are turned on and in my case they are not. So the only event that comes close is the On Exit which does work but I would like to know if there is a way to update the totals on the main form without leaving the subform.

Update, the following code fixed my issue with the update after deletion of a subform record.
Code:
Private Sub Form_Delete(Cancel As Integer)
   Me.Parent!Subtotal = Me.SubformTotal - Me!ItemTotal
   Me.Parent!OrderTotal = Me.Parent!Subtotal + Nz(Me.Parent!Freight)
End Sub
 
Last edited:
Does the current event work for you? It would fire when change records, which would (should) occur after you deleted a record.
 
try the on current event?

perhaps have a form level variable called 'recordDeleted'

in the ondelete event set it to true

in the current event code something like

Code:
if recorddeleted then
    parent.totalcontrol.requery
    recorddeleted=false
end if
 
I updated my post while you were posting pbaldy & CJ. It's fixed. In my case the total on the main form was bound. And yes, I know you are not suppose to store calculated values but this is more of an experiment to see what is possible.
 
Glad you got it sorted.
 
Anything is possible. Doesn't mean you should go for it.
 

Users who are viewing this thread

Back
Top Bottom