Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    dvbman is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    2

    calculate total of line item sales in a subform

    just signed in here for the first time - trying to figure out how to calculate a total in a form/subform to display the total sales of line items in the subform. I have tried a few things but nothing I tried is working. Is it possible to do this? ..if so, how do I approach it?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If the subform is in Datasheet view, while open in form (not design) view, click the subform then click the Totals button on the ribbon. This will open a totals row at bottom of subform. Select Sum from the dropdown list below the column you want to sum.

    If the subform is in Continuous or Single view, can have a textbox in form header/footer with expression: =Sum([fieldname]). You can do this in Datasheet view but the header/footer sections will not show, however, a textbox on main form can reference the subform textbox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dvbman is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    2
    I had tried your Single view suggestion previously and was getting a "#Error" in the box... not sure what else to try. The field I want a total on is a calculated field in the subform, a result of multiplying the quantity sold (an entered field in the subform) by the product price (a field pulled in from the product table). The resulting line item "total" displays, but then I can't get a total of that column. Does something else need to be set up that I am missing? (Thanks for responding by the way!)

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Aggregate function must reference field(s) in the form RecordSource, cannot reference controls.

    Could include the Product table in the form RecordSource (join type "Include all records from Sales and only those from Product that match")

    Do calc in the query and reference that constructed field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Just a note for consideration

    Be cautious of your table design. If you record selling price in the Product table, you will lose all history if you change the selling price.

    All historic order/sales will be updated to use the new sellingprice. You should consider adding 'AgreedToPrice" and Quantity in the actual OrderDetail record.
    That is the Price that that product sold for on this transaction - it could be clearance, loyalty price, negotiated... and will not affect historic Orders.


    Good luck with your project.

  6. #6
    TommyK is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    28
    I'm missing step somewhere. Do I open the Form (with form header and subform), then click on the subform? Or do I open the Subform, by itself, in form mode? Either way I go I cannot find the "the Totals button on the ribbon."

    Is "the Totals button on the ribbon" under the Home, Create, External Data, or Database Tools tab?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is this a normal form/subform arrangement - not a navigation form?

    The Totals button is on Home tab in the Records group. It looks like Sigma symbol and has label 'Totals'.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    TommyK is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    28
    "Is this a normal form/subform arrangement - not a navigation form?" What does that mean? I'm thinking normal, but I don't know what 'navigation form' means.
    Last edited by TommyK; 11-25-2014 at 11:54 AM. Reason: clarify my response

  9. #9
    TommyK is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    28
    Okay, so I now have a total under the desired subform column, which displays whether it is opened as just the subform with all records totaled, and while part of the controlling form with only the records which apply to the main form. Now how do I get that total to show up on the main form outside the subform box?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Then must use the other option I describe in post 2.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    TommyK is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    28
    So, how do I reference the field in the subform's footer? It is a text box with: "=Sum([quantity]*
    [List Price / Unit])" in it. The two fields are from a query which pulls in the following fields from a table: [quantity] and
    [List Price / Unit]. The query also multiplies the quantity and list price fields thus: "ExtPrice: IIf([status]="c",0,[Order Detail]![quantity]*[Order Detail]!
    [List Price / Unit])" (the "c" is a switch that identifieds a 'canceled' item so as to not use it's value to calculate the order's total'. FWIW, the subform's footer text box has a label which reads "Form Total:". This footer's text box shows in the subform while in Design View but not in Form View as you described.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If you have the calc in query then why not refer to that calculated field in the Sum?

    What is name of subform and textbox in footer? Expression on main form would be like: =[subformname]![textboxname]

    The textbox in footer will not show if the subform is set for Datasheet view.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    TommyK is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    28
    Quote Originally Posted by June7 View Post
    If you have the calc in query then why not refer to that calculated field in the Sum?
    I tried that but got the dreaded: "#Error"


    What is name of subform and textbox in footer?
    "Order Detail subform". The main form is "Order Detail".


    Expression on main form would be like: =[subformname]![textboxname]
    I've tried this by typing by hand, then tried by using Property Sheet>Expression Builder. Building the expression: "=Sum([Forms]![Order Detail subform]![Text22])"
    [Text22] being the system assigned title of the text box in 'Order Detail subform'.


    The textbox in footer will not show if the subform is set for Datasheet view.
    This I understand

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    No, cannot use aggregate function with a control name. Remove Sum from the expression of main form control. Don't need the [Forms]! prefix.

    I always give subform container a name different from the object it holds, like ctrDetails.

    =[ctrDetails].[Form].[Text22]
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    TommyK is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    28
    Quote Originally Posted by June7 View Post
    No, cannot use aggregate function with a control name.
    Can you explan Aggregat function. What function(s) are/is being aggregated.

    Remove Sum from the expression of main form control. Don't need the [Forms]! prefix.

    I always give subform container a name different from the object it holds, like ctrDetails.
    I changed the subform to ctrDetails subform. All Hades broke loose. the main form couldn't find it's subform....

    =[ctrDetails].[Form].[Text22]

    Wait, it seems to have worked. I changed the subform back to 'Order Detail subform', then somehow when I made the changes then immediately displayed the form in Form View, then went to Display view, then back the number magically appeared!

    The box on the Main form, outside the subform box is: "=([Order Detail subform]![Text22])" where Text22 is the name of the text box within the sub-form "Order Detail subform"


    The Sum of (the Sum of [quantity] times [unit price]) is now showing up in the Detail section AND the footer section of the 'Order Form'.


Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 12-16-2013, 01:43 PM
  2. Calculate Sales of Previous Months
    By v!ctor in forum Queries
    Replies: 1
    Last Post: 09-07-2013, 01:36 PM
  3. calculate total weight from subform
    By msasan1367 in forum Access
    Replies: 1
    Last Post: 08-05-2013, 12:06 AM
  4. Line item query
    By michaeltorpedo in forum Queries
    Replies: 9
    Last Post: 05-02-2012, 01:17 PM
  5. computing total sales per day using query
    By joms222 in forum Queries
    Replies: 0
    Last Post: 03-09-2009, 10:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums