AfterDelConfirm Event

D

Doug Leveille

I have a form that contains a continous subform. If a
record is deleted in the subform, I want to recalculate
the total of the records from the subform and display it
on the main form. I have to code to recalculate the
total in the AfterDelConfirm Event. When I step thru the
code I notice that the deleted record is still being
included in the calculation. For example, if my subform
has three records $100, $200, and $300, the total on my
main form is $600. If I delete the $200 record, the
total should be $400, but when the AfterDelConfirm event
totals the recordset, it still includes the $200 record
and calculates the total as $600.

The AfterDelConfirm event calls the following function to
sum the records:
Function calc_invoice_amount(intinvoicenbr As Long) As
Currency
On Error GoTo Err_calc_invoice_amount

'this function calculates the invoice total for an invoice
Dim rsacctdetail As New ADODB.Recordset
Dim cn As Connection
Dim strsql As String

Set cn = CurrentProject.Connection

'accumulate invoice detail records that are taxable
strsql = "select sum(extendedamount) as invoiceamount
from tblacctdetail where documentnbr = " & intinvoicenbr
& " and documenttype = 'IN'"
With rsacctdetail
.Source = strsql
.ActiveConnection = cn
.CursorType = adOpenKeyset
.LockType = adLockReadOnly
.Open
End With

If rsacctdetail.EOF Or IsNull(rsacctdetail
("invoiceamount")) Then
calc_invoice_amount = 0
Else
calc_invoice_amount = rsacctdetail
("invoiceamount")
End If

exit_calc_invoice_amount:
On Error Resume Next
rsacctdetail.Close
Set rsacctdetail = Nothing
Exit Function

Err_calc_invoice_amount:
MsgBox Err.description
Resume exit_calc_invoice_amount

End Function
 

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