Results 1 to 4 of 4
  1. #1
    Dax77 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    2

    Post Sum Query not displaying results in text box

    I have a sql query that is calculating the sum of a column and I want this result to be displayed into a text box. I am 99% certain my sql code is correct, not sure why it is not displaying in the text box.

    Private Sub Client_Id_AfterUpdate()




    Me.Text372 = Date
    Me.Text370 = User_Name()




    Dim db As Database
    Dim rs As DAO.Recordset ''Requires reference to Microsoft DAO x.x Library
    Dim rs1 As DAO.Recordset
    Dim rs2 As DAO.Recordset
    Dim rs3 As DAO.Recordset
    Dim sSQL As String
    Dim sSQL1 As String
    Dim sSQL2 As String
    Dim sSQL3 As String






    sSQL2 = "Select Sum(Table.Column) as Result " & _
    "FROM Table " & _
    "WHERE (Table.[Column])= " & Date & " and (Table.[Column])= 'Tax Fund Checks Pending' and (Table.[Column])= " & Nz(Me.Client_ID) & _
    " Group by (Table.[Column])"

    Set db = CurrentDb
    Set rs2 = db.OpenRecordset(sSQL2)
    Debug.Print sSQL2
    If rs2.RecordCount > 0 Then
    Me.Text358 = rs2!Result
    Else
    Me.Text358 = ""
    End If


    Set rs2 = Nothing
    Set db = Nothing

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Is the textbox on form or report? Is the form/report bound? Why are you using VBA and not aggregate function in a textbox ControlSource in form or report footer?

    Why are you grouping on the same field to be summed? This will not sum anything.

    You have a field named Column?
    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
    Dax77 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    2
    Here is what I am currently using:

    sSQL2 = "Select Sum(Daily_Tally_Log.[Number_Incoming_Checks]) as Result " & _
    "FROM Daily_Tally_Log " & _
    "WHERE (Daily_Tally_Log.[Log_Date])= " & Date & " and (Daily_Tally_Log.[Check_Receipt])= 'Tax Fund Checks Pending' and (Daily_Tally_Log.[Client_ID])= " & Nz(Me.Client_ID)

    Set db = CurrentDb
    Set rs2 = db.OpenRecordset(sSQL2)
    Debug.Print sSQL2
    If rs2.RecordCount > 0 Then
    Me.Text358 = rs2!Result
    Else
    Me.Text358 = "0"
    End If


    Set rs2 = Nothing
    Set db = Nothing



    Textbox is on a bound form and the result of the query are fed to the record of a table thru that textbox.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    GASP! You are saving aggregate data? Why? This is indicative of poor relational database design. If aggregate value can be calculated for saving then it can be calculated as needed. This is the preferred practice. Saving calculated data, especially aggregate calcs, is not desirable. There is risk for raw data and the saved calc to get out-of-sync.
    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: 3
    Last Post: 09-02-2013, 04:33 PM
  2. Replies: 1
    Last Post: 10-01-2012, 12:31 PM
  3. Displaying query results in form
    By celito in forum Access
    Replies: 2
    Last Post: 08-27-2011, 09:14 AM
  4. Replies: 9
    Last Post: 12-13-2010, 09:25 PM
  5. Displaying query results within a form
    By Remster in forum Forms
    Replies: 5
    Last Post: 10-05-2010, 09:56 PM

Tags for this Thread

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