Results 1 to 12 of 12
  1. #1
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284

    Display the Sum of a Query Result in Decimals

    Hello Again...



    The query populates a ListBox from which I loop through to sum the Hours Worked column...

    The issue I am having is that the TextBox won't display decimals.

    I have changed as many setting as I can and still nothing?

    could the source have something to do with this...

    Thanks for your help...

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    First you say you are populating a ListBox then you say TextBox won't display decimals. What has listbox got to do with the textbox? What source - the listbox RowSource?
    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
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The issue I am having is that the TextBox won't display decimals.
    If the text box is bound to a table field of type integer, then it won't display decimals. If the textbox is unbound, or is bound to a field that is numeric but not integer, then you need to set the Format property to display a fixed number of decimals.

  4. #4
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Hey June ~

    The ListBox displays the results of the query of which there is a column indicating the hours each employees enters at the end of each day. Thus an employee may enter 8, 8 7.5, 6.75, 8.5 etc, etc.

    Once the ListBox is populated with the query results I loop through the values in the 'HoursWorked' column to sum the total hours and I want to display that result in a TextBox. If my code were to add the results

    of the hours I posted in the previous sentence it would display in the TextBox 38 instead of 38.75

    The source in this instance is the table data.

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    First, the field on the table must be Double, or at least no kind of integer. Second, are the decimals being displayed in the query for the listbox correctly? If so, then the format of the textbox should be such that decimals are displayed.

  6. #6
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Hello Aytee ~

    Yes, the ListBox does display the decimals correctly, so I will check the field and TextBox properties/formatting when I get to work in about an hour...Thanks as always for your help

  7. #7
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Update...

    Apparently, the reason the TextBox is not showing the decimals is because the Sum loop is not recognizing them. When I step through the Sum loop and stop on the sum variable after each pass the intelisense is showing the whole number and not decimals after it.

    Thus, if an employee enters 9.75 and the ListBox shows 9.75 when it is summed the intelisense shows 9

    Here is the Sum Loop
    Code:
    Dim LstRows As Integer
    Dim LstSum As Integer
    LstRows = Me![LstTempTimeView].ListCount
    X = 1
    Do
    LstSum = LstSum + (Me![LstTempTimeView].Column(6, X))
    X = X + 1
    Loop Until X = LstRows
    Me![Text4] = LstSum
    Can anyone see a reason why this loop wont recognize the decimals?

    When I place (Me![LstTempTimeView].Column(6, X)) into the immediate window it will return the correct result

    Thanks as always...

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    LstSum is declared as an Integer. Integer cannot have decimal. Declare LstSum as Double.
    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
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    June ~ You Rock!!!! Simple as that!!

    Thank you very much...

    Quick question... Is looping through the rows in the ListBox the best way to find the sum... (it is the only way I know in my Access infancy)

    Thanks Again...

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    What is the RowSource of the listbox? Could probably use the same filter criteria in an expression using DSum() domain aggregate function. However, domain aggregate functions can perform slowly in query and in 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.

  11. #11
    RunTime91 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    284
    Hey June ~

    The RowSource is set at RunTime ~ Code is below
    Code:
    Me.LstTempTimeView.RowSource = "SELECT tbl_AssocInfo.DB_ID, tbl_AssocInfo.Assoc_ID, [tbl_AssocInfo].[First_Nm] & "" "" & [tbl_AssocInfo].[Last_Nm] AS Name, tblTeamAssignment.TeamID, tblContractorInfo.TempAgency, tblDailyHoursWorked.Entered, tblDailyHoursWorked.HoursWorked, tblTeamAssignment.TeamEnd " & _
    "FROM ((tblDailyHoursWorked INNER JOIN tbl_AssocInfo ON tblDailyHoursWorked.DB_ID = tbl_AssocInfo.DB_ID) INNER JOIN tblContractorInfo ON tbl_AssocInfo.DB_ID = tblContractorInfo.DB_ID) INNER JOIN tblTeamAssignment ON tbl_AssocInfo.DB_ID = tblTeamAssignment.DB_ID " & _
    "WHERE (((tbl_AssocInfo.Assoc_ID) Like ""C*"") AND ((tblTeamAssignment.TeamID)=[Forms]![frmTempTimeTest]![CboTeamName]) AND ((tblDailyHoursWorked.Entered) Between [Forms]![frmTempTimeTest]![TxtBegDate] And [Forms]![frmTempTimeTest]![TxtEndDate]) AND ((tblTeamAssignment.TeamEnd) Is Null));"

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    That's a lot of criteria but something like:

    DSum("HoursWorked", "query name here", "Assoc_ID Like 'C*' AND TeamID=[Forms]![frmTempTimeTest]![CboTeamName] AND Entered Between [Forms]![frmTempTimeTest]![TxtBegDate] And [Forms]![frmTempTimeTest]![TxtEndDate] AND TeamEnd Is Null")

    or concatenate variable references:

    DSum("HoursWorked", "query name here", "Assoc_ID Like 'C*' AND TeamID=" & [Forms]![frmTempTimeTest]![CboTeamName] & " AND Entered Between #" & [Forms]![frmTempTimeTest]![TxtBegDate] & "# And #" & [Forms]![frmTempTimeTest]![TxtEndDate] & "# AND TeamEnd Is Null")
    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. Display result when data missing
    By roarcrm in forum Queries
    Replies: 5
    Last Post: 08-01-2014, 08:27 PM
  2. Replies: 1
    Last Post: 07-03-2014, 08:27 PM
  3. Display Query Form as a Result
    By rescobar in forum Forms
    Replies: 2
    Last Post: 08-19-2013, 11:31 AM
  4. Append query dropping decimals
    By thedanch in forum Queries
    Replies: 2
    Last Post: 08-02-2012, 02:32 PM
  5. HELP! Display a query result into form
    By leanne in forum Forms
    Replies: 15
    Last Post: 06-23-2010, 09:18 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