Sum to be able to be viewed on a Report!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GLEberts
    New Member
    • Mar 2008
    • 51

    #1

    Sum to be able to be viewed on a Report!

    I have a text box [txttotalmatcost] with the following in the control source

    =CDbl(nz([txtmatcost1],0))+CDbl(nz([txtmatcost2],0))+CDbl(nz([txtmatcost3],0))+CDbl(nz([txtmatcost4],0))+CDbl(nz([txtmatcost5],0))+CDbl(nz([txtmatcost6],0))+CDbl(nz([txtmatcost7],0))+CDbl(nz([txtmatcost8],0))+CDbl(nz([txtmatcost9],0))+CDbl(nz([txtmatcost10],0))

    This works well for the sum of above text boxes.
    However it is not bound to the txt box - I put it in the control source

    What I want to do is bound the text box so I can easily bring up the sum so I can use the answer in various reports.

    1st question is this the proper way to do this? or should it be done in a query?
    2nd question if it is - where do I input the above and how?

    Summary of what I am looking for is to have the sum of the text boxes to be able to be viewed on a report.

    Thanks for your direction
    Gary
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. Binding is not really what you mean here - a bound control is one which is bound to an underlying field in a table. It is not normal practice to store computed values in a table - these should be computed on demand, using a query to do so.

    You do need to be clear, however, that whilst you are summing textbox control values at the moment these are just a means of displaying data on a form. It is the fields of the underlying query or table to which the textboxes are bound which should be summed, not the textbox values themselves. That way you are not dependent on the form being open at the time you do the computation.

    My advice therefore would be to add the computation as an additional computed field with a suitable name to whatever query you currently use as the source for your form. You will then have an up-to-date summed value available every time you run the query.

    The computed field is entered into a blank column in the Access query editor as something like this:

    Code:
    Summary Total: CDbl(Nz([firstfield], 0)) + CDbl(Nz([secondfield], 0)) ... CDbl(Nz([Lastfield], 0))
    Equivalently, in SQL this is just

    Code:
    Select <your existing fields>, CDbl(Nz([firstfield], 0)) + CDbl(Nz([secondfield], 0)) ... CDbl(Nz([Lastfield], 0)) As [Summary Total]
    FROM <name of your query or table>...
    -Stewart

    Comment

    • GLEberts
      New Member
      • Mar 2008
      • 51

      #3
      Thanks Stewart for your reply.
      Makes sense and the answer I expected. Did what you suggested and worked well.
      Thanks for your help
      Gary

      Comment

      Working...