Al, I already tried that, but it made no difference.
I also converted the database to an XP version and that made no difference
either.
There seems to be a problem with the code working in the oncurrent event.
I have listed the code below: (NB: tbxOrdersTotal , tbxReceiptsTotal and
tbxAdjustmentTotal are not really required. I used them to see what was
happening.)
Public Sub GetSubformTotals()
On Error GoTo Err_ErrorCheck
Dim dbMyDB As DAO.Database, rst As DAO.Recordset
Set dbMyDB = CurrentDb
Dim varOrdersTotal As Long
Dim varReceiptsTotal As Long
Dim varAdjustmentTotal As Long
Set rst = Forms![frmCustomer]![frmCustomerOrderSubform].Form.RecordsetClone
rst.MoveFirst
rst.MoveLast
If Nz(rst.RecordCount, 0) > 0 Then
varOrdersTotal =
Forms![frmCustomer]![frmCustomerOrderSubform].Form.tbxSumOrderTotal
Else
varOrdersTotal = 0
End If
Me.tbxOrdersTotal = varOrdersTotal
Set rst =
Forms![frmCustomer]![frmCustomerReceiptSubform].Form.RecordsetClone
rst.MoveFirst
rst.MoveLast
If Nz(rst.RecordCount, 0) > 0 Then
varReceiptsTotal =
Forms![frmCustomer]![frmCustomerReceiptSubform].Form.tbxSumReceiptsAmount
Else
varReceiptsTotal = 0
End If
Me.tbxReceiptsTotal = varReceiptsTotal
Set rst =
Forms![frmCustomer]![frmCustomerAdjustmentSubform].Form.RecordsetClone
rst.MoveFirst
rst.MoveLast
If Nz(rst.RecordCount, 0) > 0 Then
varAdjustmentTotal =
Forms![frmCustomer]![frmCustomerAdjustmentSubform].Form.tbxSumAdjustmentTota
l
Else
varAdjustmentTotal = 0
End If
Me.tbxAdjustmentTotal = varAdjustmentTotal
rst.Close
dbMyDB.Close
Me.tbxBalanceOwing = varOrdersTotal - varReceiptsTotal + varAdjustmentTotal
Me.tbxBalanceOwing.Visible = True
Me.tbxName.SetFocus
Me.CmdGetCustomerBalance.Visible = False
Exit_ErrorCheck:
Exit Sub
Err_ErrorCheck:
' MsgBox Err.Description
Resume Next
Resume Exit_ErrorCheck
End Sub
John.
Al Borges said:
Hi John:
You can try calling up the clickbutton OnClick event...
Regards,
Al
John Baker said:
Thanks very much for your help Al.
I tried your first method without success. I was more or less already doing
what you had suggested.
I have had partial success with your recordset method. It works if I put
the code into a command button but ideally I would like to use the
code
with
the oncurrent event. However when I put the code into the oncurrent event
the code does not work. Not sure why. If I step over each line of code in
debug mode it seems to work but otherwise when I go from record to record
the code doesn't seem to work. It's like it does not refresh itself.
Any ideas?
John.
"Al Borges" <alborgmd at yahoo dot com> wrote in message
Hi John:
You should use either the Nz() function or the If IsNull() then set the
amount to zero if null. That might be enough... That should fix your
problem, s.a. with this sample (code should be placed in the control
source
property of a sum field of each recordset):
Nz(DSum("balance", "accounts", "[ACCT] = Forms![*Ledger form]![ACCT]"),0)
Then you could reference them:
zz = forms![parentform]![childform1].form![sum1] +
forms![parentform]![childform2].form![sum2] etc etc etc
Another method could be the recordsetclone... check each form for the
presence of records through a recordsetclone procedure (similar to
the
one
that I posted for conditional tabs just yesterday):
Dim xx as long, yy as long, zz as long
Dim rst as recordset
Set rst = Forms![YourFocusForm]![Subform1].form.RecordsetClone
rst.movefirst
rst.movelast
If rst.recordcount > 0 Then
xx = DSum("balance", "accounts", "[ACCT] = Forms![*Ledger form]![ACCT]")
else
xx = 0
End If
Set rst = Forms![YourFocusForm]![Subform2].form.RecordsetClone
rst.movefirst
rst.movelast
If rst.recordcount > 0 Then
yy = DSum("balance", "accounts", "[ACCT] = Forms![*Ledger form]![ACCT]")
else
yy = 0
End If
etc etc etc
zz = xx + yy
Let me know how it works for you.
Regards,
AL
Can anyone please help.
I am trying to calculate a total in a textbox on a main form where the
values I want are contained in a textbox in the form footer on
each
think