Results 1 to 10 of 10
  1. #1
    twildt is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    56

    'Total'(sum) Box from a Different Record Source

    I can't get my code to SUM correctly. I'm getting #Error in the textbox.



    I have a Mainform with a textbox referencing another textbox(performing the SUM function) on a subform. I think the problem is this subform is based off a query and the field I am trying to SUM is formatted.

    Here is some detailed info:

    Query code:
    HTML Code:
    SELECT [Work Hours].Employee, [Work Hours].[Date Worked], [Work Hours].[Work Type], [Work Hours].[Work Task], FormatMinutesAsHMM([MinutesWorked]) AS Hours, [Work Hours].[Work Descripton]
    FROM [Work Hours] LEFT JOIN [Employees Extended] ON [Work Hours].Employee = [Employees Extended].ID
    WHERE ((([Work Hours].[Date Worked])=Date()) AND (([Employees Extended].[User Login])=[Forms]![frmLogin]![LoginName]));
    The field in question is: FormatMinutesAsHMM([MinutesWorked]) AS Hours

    Subform textbox(name is totalhours) =FormatMinutesAsHMM(Sum([Hours]))
    Mainform textbox =[NavigationSubform].[Form]![totalhours]

    The table "Work Hours", field name "MinutesWorked", has data entered in as minutes(15, 30, 90, etc)

    My FormatMinutesAsHMM module is converting those minutes into h:nn

    The Subform based on the query is in datasheet view for the users so that "totalhours" textbox is in the footer.

    How can I SUM this field and show it on my Mainform? Why is my current configuration displaying "#Error" instead of the SUM of the data?

  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,973
    Can't sum h:nn, that is text not a number.

    Need to sum the original minutes field, then format as h:nn.
    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
    twildt is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    56
    How do I SUM original field when the record source of the subform is a query?

    I build the query for the reason to filter out the data to just "today(date()". I am only returning data entered today and only today do I want the SUM field calculating.

  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,973
    Shouldn't matter if the RecordSource is a table or query as long as the requisite field is included. Do the Sum in textbox in subform form footer section. If the subform is in Form or Continuous view, the footer can be displayed, if in Datasheet view then a textbox on main form can reference the textbox in the subform.
    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
    twildt is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    56
    Quote Originally Posted by June7 View Post
    Shouldn't matter if the RecordSource is a table or query as long as the requisite field is included. Do the Sum in textbox in subform form footer section. If the subform is in Form or Continuous view, the footer can be displayed, if in Datasheet view then a textbox on main form can reference the textbox in the subform.
    Thats what I am doing. textbox in footer of subform, then textbox on mainform referencing the textbox in subform. I'm getting that #Error.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,973
    If you can have a field for the h:nn calculation then why can't you include the original MinutesWorked 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.

  7. #7
    twildt is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    56
    I added the field for the MinutesWorked. I don't want this field visible to the users because it's not formatted. This is confusing to them. So if I can hide that field and still use it that would be great because now that I added that field and I am referencing it instead my SUM is working.

    So how can I hide it from the users? The view is datasheet view for the users. I tried going to the design of the query and unchecking the "Show" checkbox but that removes it from the query completely.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,973
    If there is no textbox bound to the field, then it should not show in the form but the field is still available for the Sum.

    Or set the textbox Visible property to No and delete associated label.
    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.

  9. #9
    twildt is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    56
    That did it. I added the text box and bound it because I didn't think it would work without the text box... That was my fault. Thanks!

    Resolution:
    Step 1. Added another field to my query with the source data(unformatted).
    Step 2. Did not create a bound text box on my subform but SUM'd the field in my footer textbox.
    Now the total's textbox reference on the main form is displaying the totals from the subform footer textbox!

  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,973
    Should note that doesn't always hold true with reports. Many times I tried to reference field without bound textbox and the report errors.
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-18-2013, 09:15 PM
  2. Getting a total of all 24 values in one record
    By TheMegaSage in forum Queries
    Replies: 3
    Last Post: 07-25-2013, 12:44 PM
  3. Getting to SQL in report record source
    By Monterey_Manzer in forum Reports
    Replies: 3
    Last Post: 12-04-2012, 01:44 PM
  4. Replies: 14
    Last Post: 05-25-2012, 02:40 AM
  5. Forms' Record Source
    By Progress2007 in forum Programming
    Replies: 11
    Last Post: 07-27-2009, 11:04 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