Results 1 to 10 of 10
  1. #1
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9

    Get Sum of Column X of Subform in Main Form

    Hi Expert,

    i Have a Main Form called Customer Details, in this form i put Transaction Subform that contains Transaction Details of all Costumer

    i Liked these forms with Customer ID so if i see Customer X it means i see Customer X Transaction Details

    i want summerized Payment Columns of Transaction of Customer X in Textbox, see this code:
    =Sum(Nz([Transaction subform].[Form]![Payment],0))

    This Expression returns Error!

    and i don't know why

    Thanks

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Have you tried putting your expression in the footer or header of the subform?

  3. #3
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9

    Re: Get Sum of Column X of Subform in Main Form

    Yes, error still remaining

  4. #4
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9

    Re: Get Sum of Column X of Subform in Main Form

    Is anybody here to solve this issue...?

  5. #5
    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
    First off, when using Functions like Sum() you must use the Field name, not the Textbox name! If they're both the same (as Access names them when a Field is dragged onto a Form) it will work, but if the two names are different, you must use the name of the Control's underlying Field.

    To Calculate a Total, in Form Design View, in the SubForm's Footer, place a Unbound Textbox.

    To simply total a Single Field, the Control Source of this new Textbox would be

    =Sum([Field1])

    If the Field is a Calculated Value you must Sum() the Calculation, not the Field itself!

    So, if

    MySubTotal = Field1 + Field2

    You cannot use

    =Sum([MySubTotal])

    Instead, you must use

    = Sum([Field1[ + [Field2])

    Now, to place the totals on the Main Form:

    Create an Unbound Textbox, and use this in its Control Source

    =SubformName.Form!SFTotalTextboxName

    Note that SubformName has to be the name of the Subform Control, and not the name of the Form the Subform is based on, unless the two are the same.

    SFTotalTextboxName is the name of the Textbox on the Subform where the calculation is done.

    Linq ;0)>

  6. #6
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9

    Re: Get Sum of Column X of Subform in Main Form

    Quote Originally Posted by Missinglinq View Post
    First off, when using Functions like Sum() you must use the Field name, not the Textbox name! If they're both the same (as Access names them when a Field is dragged onto a Form) it will work, but if the two names are different, you must use the name of the Control's underlying Field.

    To Calculate a Total, in Form Design View, in the SubForm's Footer, place a Unbound Textbox.

    To simply total a Single Field, the Control Source of this new Textbox would be

    =Sum([Field1])

    If the Field is a Calculated Value you must Sum() the Calculation, not the Field itself!

    So, if

    MySubTotal = Field1 + Field2

    You cannot use

    =Sum([MySubTotal])

    Instead, you must use

    = Sum([Field1[ + [Field2])

    Now, to place the totals on the Main Form:

    Create an Unbound Textbox, and use this in its Control Source

    =SubformName.Form!SFTotalTextboxName

    Note that SubformName has to be the name of the Subform Control, and not the name of the Form the Subform is based on, unless the two are the same.

    SFTotalTextboxName is the name of the Textbox on the Subform where the calculation is done.

    Linq ;0)>
    Wow! Big Thanks for your complete answer:thumbup:

  7. #7
    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
    Glad we could help!

    Linq ;0)>

  8. #8
    smithse is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    37
    Hi all,

    I also find that sometimes the Nz() function returns an error! I now no longer use this function at all!!
    I have had exactly the same experience and requirement while trying to get the value of a control on a subform, and resorted to writing a separate function to get the value.

    Glad you solved your problem though!

  9. #9
    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 smithse View Post

    ...I also find that sometimes the Nz() function returns an error! I now no longer use this function at all!!
    In seven years of trolling half-a-dozen Access forums, 8-10 hours a day, I've never seen a report of Nz() returning an error! I have, however, seen many instances when it was applied incorrectly!

    There are workarounds, of course.

    If (Me.ControlName & vbNullString) = "" Then

    comes to mind, and there are probably others!

    And writing a UDF to replace two Controls Sources

    =Sum([Field1])

    =SubformName.Form!SFTotalTextboxName


    seems a bit of overkill, but as John Lennon once wrote, "Whatever gets you through the night!"

    Linq ;0)>

  10. #10
    smithse is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    37
    Quote Originally Posted by Missinglinq View Post
    In seven years of trolling half-a-dozen Access forums, 8-10 hours a day, I've never seen a report of Nz() returning an error! I have, however, seen many instances when it was applied incorrectly!

    There are workarounds, of course.

    If (Me.ControlName & vbNullString) = "" Then

    comes to mind, and there are probably others!

    And writing a UDF to replace two Controls Sources

    =Sum([Field1])

    =SubformName.Form!SFTotalTextboxName


    seems a bit of overkill, but as John Lennon once wrote, "Whatever gets you through the night!"

    Linq ;0)>
    Hi Missinglinq,

    I was able to generate a runtime error with the Nz() function in a db built in Access 2010 on a Windows 7 box, and running in the Access Runtime 2010 on WinXP and Windows Vista. I got rid of the Nz() function which I was using in several forms and queries and my problem went away.

    LOL, I have seen suggestions of using 2 controls like that.... Pretty ugly, but as you say, whatever works. Oh, and no, I didn't have to resort to that! I simply excluded Nulls in my query.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-17-2012, 10:28 AM
  2. Subform / Main Form problems...
    By aceoftrades in forum Forms
    Replies: 4
    Last Post: 03-18-2012, 10:39 AM
  3. Replies: 3
    Last Post: 11-16-2011, 01:56 PM
  4. Totals from subform to main form
    By kathi2005 in forum Forms
    Replies: 4
    Last Post: 11-04-2011, 10:19 AM
  5. opening a second form from main/subform
    By PJPCVP in forum Database Design
    Replies: 1
    Last Post: 10-29-2010, 09:50 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