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.
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