Total function is not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MNNovice
    Contributor
    • Aug 2008
    • 418

    Total function is not working

    I am trying to get a grand total amount from a sub form to a main form. The text box on the sub form is called "Total". I created a text box on the main form and used =Sum([Total]) to get the grand total. However, it returns #Error message.

    What am I doing wrong?
  • timber910
    New Member
    • Oct 2006
    • 39

    #2
    You need to call the total from the sub form to the main form.

    Post your code around this field from the sub form and what your trying to put it into on your main form.


    Originally posted by MNNovice
    I am trying to get a grand total amount from a sub form to a main form. The text box on the sub form is called "Total". I created a text box on the main form and used =Sum([Total]) to get the grand total. However, it returns #Error message.

    What am I doing wrong?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32663

      #3
      Refer to Referring to Items on a Sub-Form for help with this. Let us know if you still have problems.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by MNNovice
        I am trying to get a grand total amount from a sub form to a main form. The text box on the sub form is called "Total". I created a text box on the main form and used =Sum([Total]) to get the grand total. However, it returns #Error message.

        What am I doing wrong?
        You simply cannot reference the Aggregate Expression in the SubForm from the Main Form. In the Orders/Orders SubForm Pair in the Northwind Sample Database, the Order SubTotal is calculated in the Orders SubForm in the following manner:
        Code:
        =Sum([ExtendedPrice])
        To achieve this same result in the Main Form (Orders) would require:
        Code:
        =DSum("[ExtendedPrice]","Order Details Extended","[OrderID]= " & [Forms]![Orders]![OrderID])
        Does this make sense to you?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32663

          #5
          Fair point ADezii. I missed that.

          Just reread the OP and realised it shows a value of #Error, rather than any error message as such.

          Comment

          • MNNovice
            Contributor
            • Aug 2008
            • 418

            #6
            Hello all:

            Thanks for your input. I will read and try to understand how to better write this formula. Meanwhile I solved my problem this way:

            Main form: frmGrants
            Sub form: sfrmGrantBudget
            to record aggregate figures from the line items of the sub form a text box was added to the footer: txtTotal
            To record the grand total in the main form's footer the text box is called: txtGrandTotal

            When I entered this formula in the control for txtTotal: =Sum([Total]) I got yet another error message (#Error). Well, I then found out I cannot use a control's name with the Sum function. I changed the formula to read as:


            =sum([BudgetAmount]) + sum([ChangeAmount]) (BudgetAmount and ChangeAmount are two fields on my sub form)

            and then added this to the main form's text box (txtGrandTotal)

            =sfrmGrantBudge t.Form!txtTotal

            So this is what I did and it solved my problem.

            Thanks for your help.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32663

              #7
              This is actually a better solution, and was what I was intending to suggest. I realised however, that expressing this without any information as to what is available on your form would almost certainly just add further confusion.

              Suffice to say, you've discovered a very good (and most correct) method of producing the result you want. This uses data already available to you rather than shooting off to the table repeatedly, using a Domain Aggregate function.

              This should not be taken in any way as a criticism of ADezii's post, as he was just as much in the dark as I, so he gave the best option he could suggest from what we knew. Congratulations though, for coming up with such a good answer.

              Comment

              • MNNovice
                Contributor
                • Aug 2008
                • 418

                #8
                NeoPa:

                Thanks for the compliments. You know it's only natural to have some of brilliance rub off of all these Tech Gurus (like you and others on Bytes.com) I am talking everyday...

                Thanks.

                Comment

                Working...