SQL Query to Sum “On the Fly”

gsandy

Registered User.
Local time
Today, 16:16
Joined
May 4, 2014
Messages
104
I have used the following code (with the help of others) to make a query "On the Fly". It works but the results are in Detail (line by line) form for each Job Number.
How do I get it to Sum the result rather than Detail? Thanks Sandy.
Code:
Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String
    Set db = CurrentDb
    Set qdf = db.QueryDefs("JobSummaryQuery")
   
    strSQL = "SELECT tblHourEnter.* " & _
             "FROM tblHourEnter " & _
             "WHERE 1=1 " ' the 1=1 is just a dummy to make things a little easier and you can prefix everything with AND
    If Not IsNull(Me.cmbJobList.Value) Then
             strSQL = strSQL & " AND tblHourEnter.JobNumber=" & Me.cmbJobList.Value & " "
    End If
    If Not IsNull(Me.cmbStaff.Value) Then
            strSQL = strSQL & " AND tblHourEnter.Staff_ID=" & Me.cmbStaff.Value & " "
    End If
    strSQL = strSQL & " ORDER BY tblHourEnter.JobNumber;"
    qdf.SQL = strSQL
    DoCmd.OpenQuery "JobSummaryQuery"
    Set qdf = Nothing
    Set db = Nothing
 
I am sure it would work, but this is my first go at Access. Can you advise how I would insert it? Thanks Sandy
 

Users who are viewing this thread

Back
Top Bottom