Sum() problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • n8kindt
    New Member
    • Mar 2008
    • 221

    Sum() problem

    i don't know what to do about this one. there are some very strange things going on. i have a continuous form with a bound textbox and a bound toggle button. the textbox is named "Payment" and the toggle is named "Apply." i want to have a textbox in the footer (named TotalPayment) that calculates the sum of whatever is in the textbox, provided that the bound toggle button is set to True. i created a function for this purpose. here it is:

    Code:
    Function AmountTF(TF, Amount) As Double
    If TF = True Then
    AmountTF = Nz(Amount, 0)
    Else: AmountTF = 0
    End If
    End Function
    at first i tried placing this code into TotalPayment:
    Code:
    =Sum(AmountTF([Apply],[Payment]))
    i also tried placing Nz([Payment],0) and that did not change it from returning "#Error"

    my next step was to create an additional textbox in the form (named PaymentTest) to test if the function was working or not:
    Code:
    =AmountTF([Apply],[Payment])
    this returned the correct values.
    then, i set TotalPayment to
    Code:
    =Sum([PaymentTest])
    once again, the sum function does not work and returns "#Error"

    and here's the weird part, i deleted TotalPayment and created a new textbox in the footer and set it to:
    Code:
    =Sum([Payment])
    and it worked... UNTIL i placed the TotalPayment textbox back into the footer with the code:
    Code:
    =Sum(AmountTF([Apply],[Payment]))
    and now, neither one of the textboxes work. would someone kindly explain to me why this is happening and what i can do to work around this? thanks in advance for all your help
  • n8kindt
    New Member
    • Mar 2008
    • 221

    #2
    a little research has provided me a clue. perhaps i need to use DSum() instead? this solution would still leave some of the form behavior unexplained. here's my feeble attempt at generating code for the DSum() function (fyi it still returns #Error)

    Code:
    =DSum("[PaymentTest]","SplitForm")

    Comment

    • n8kindt
      New Member
      • Mar 2008
      • 221

      #3
      alright, i figured it out. i did the calculation in the underlying query rather than doing it on the form. sum() works fine now. i still don't get why it couldn't do the calculation on the form and it still would still be interesting if someone could explain why when one sum() function doesnt work, it knocks out another perfectly running sum() function. anybody?

      Comment

      Working...