Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    DunnRight is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2014
    Posts
    4

    How to Sum a total from a subform in a Text Box on the Main Form


    I am a novice at best. I have a project that I am working on in which I am trying to turn a template I found online into something I can use for my job. I work for a company that houses inventory and sells some of that inventory to customers. I have a subform on my main form that lists items sold to a specific customer and tracked by a sales order number. What I am having problems with is getting a text box on the main form to calculate the total value of the parts sold on that order. I am not sure what other info anyone may need to help me out here, but I would greatly appreciate any help offered.

  2. #2
    atuhacek is offline New
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Location
    Michigan
    Posts
    61
    I normally put a total field on the subreport pagefooter. Just a text box name txtTotal set the control property =Sum([yourfield]) make sure that the field name and text box name are different or it wil error.

    then on your main for put another textbox named txtGrandTotal and set its control property to =Reports!YourSubReport!txtTotal

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If your form is based on a query, it may be as simple as turning that Query Object into a Totals query. There is an option within the Ribbon (while in Design View of the Query Object) you can click. It is labeled "Totals" with an upper case Sigma.

    Once you have selected the Totals option you can add the Field you want to sum to your query. Employ the pulldown provided within the grid (bottom of the window) to select "Sum".

  4. #4
    DunnRight is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2014
    Posts
    4
    I am still have difficulty getting this to work. Here is a shot of the Main Form. I need the extended price of all parts sold, which are listed in the sub form, to be totaled in the Text Box "Order Subtotal" at the bottom of the main form. I have tried what atuhacek suggested which, for me produced a blank text box rather than the error I had before. Any other suggestions? I can provide more info if anyone needs it.Click image for larger version. 

Name:	Access Help.JPG 
Views:	32 
Size:	75.1 KB 
ID:	17006

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Since this is a form, not a report, don't use Reports in the reference (but that should have erred anyway).

    What is name of subform container control? I always name the container control different from the object it holds, like ctrDetails. Then try expression:

    =[ctrDetails]!txtTotal
    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.

  6. #6
    DunnRight is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2014
    Posts
    4
    So here is a shot of the sub form. Click image for larger version. 

Name:	SubForm Help.JPG 
Views:	31 
Size:	57.5 KB 
ID:	17008

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    The syntax I suggested works for me.

    Your image shows properties of the textbox, still don't know the name of the subform container control.
    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
    atuhacek is offline New
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Location
    Michigan
    Posts
    61
    You correct June7 that would have errored I forgot to address the container. And the total field goes in the page footer.

    with a subReport container As [Child26] and total field [txtMaterial]

    =Nz(Sum([Total_Bill]),0)

    this will return the total the above generates

    =IIf(IsError([Child26].[Report]![txt_MaterialTotal]),0,Nz([Child26].[Report]![txt_MaterialTotal]))

    If you put a text box on your sub Form to generate the total you can call it like the above. Change the Reports to Form and the fields to your control names. Make sure your fields and controls have different names.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    The syntax does not require the [Report] (or [Form]) reference. The simpler syntax I posted works. If want to handle possible Null (although don't really see the need to):

    =Nz([ctrDetails]![txtTotal],0)
    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.

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by ItsMe View Post
    If your form is based on a query, it may be as simple as turning that Query Object into a Totals query...
    The problem with this is that Totals Queries are always Read-Only, so the Subform itself would be Read-Only.

    ExtendedPrice is a Calculated Field

    =[Qty]*[UnitPrice]

    and Aggregate Functions cannot be run against Calculated Fields. Instead of

    =Sum([ExtendedPrice])

    you have to use Sum against the calculation, itself:

    =Sum([Qty]*[UnitPrice])

    Then, on the Main Form, you have to reference this Control on the Subform, with syntax like this

    =SubformControlName.Form!ControlNameOnSub

    Linq ;0)>
    Last edited by Missinglinq; 06-27-2014 at 07:56 PM.

  11. #11
    atuhacek is offline New
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Location
    Michigan
    Posts
    61
    @missinglinq Sum([Qty]*[UnitPrice]) Is correct

    I normally use a total field "Total As [Qty]*[UnitPrice]" then Sum the total field.

    @June7 I believe have to name a child explicitly you can't just name the control in the child

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    My example references the container control and the textbox. I tested it with my db and it worked.
    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
    atuhacek is offline New
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Location
    Michigan
    Posts
    61
    Ok. I always use formal to avoid confusion. But you are right it is implied.

  14. #14
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by atuhacek View Post
    Ok. I always use formal to avoid confusion. But you are right it is implied.
    Just to clarify, the secret to using June7's syntax of

    =[ctrDetails]!txtTotal

    is that the name of the Subform Control must be different from the name of the Form that is the Source Object of the Subform Control, and that the ctrDetails in his code is the name of the Subform Control.

    Linq ;0)>

  15. #15
    DunnRight is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2014
    Posts
    4
    I appreciate all the help, but I am still doing something wrong. Here is a shot of the subform.
    Click image for larger version. 

Name:	Subform.JPG 
Views:	23 
Size:	23.7 KB 
ID:	17041

    Here is a shot of the main form while i have the container selected for the subform.
    Click image for larger version. 

Name:	Subform Container Control.JPG 
Views:	23 
Size:	101.8 KB 
ID:	17042

    I am having problems getting the "Order Subtotal" and the "Order Total" to work. Although, I am pretty sure the "Order Total" may not be working since the "Order Subtotal" is not working.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-24-2013, 04:39 PM
  2. Replies: 2
    Last Post: 05-23-2013, 08:29 AM
  3. Replies: 8
    Last Post: 04-29-2013, 12:11 PM
  4. Replies: 9
    Last Post: 03-22-2013, 06:37 AM
  5. Replies: 4
    Last Post: 10-18-2011, 10:18 AM

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