SQL SELECT SUM or DSUM ?

  • Thread starter Thread starter Dave Ruhl
  • Start date Start date
D

Dave Ruhl

I have a report which displays data for a specified
Quarter of a year. I want to display totals from prior
Quarters for some fields. The queries I use are built in
code, based on a user-specified date, so there are no
queries saved in Access.

I tried using DSUM to get totals for certain fields, but
it only seems to work with saved queries, not SQL SELECT
statements.

How can I code, in VB, a SELECT SUM statement to return
the sum of a field when my set of records is created by
an SQL SELECT statement ?
 
Set rs = CurrentDb.OpenRecordset("SELECT Sum([Line]) As SumOfLine FROM
Table2 WHERE [Line] <5")
?rs.Fields(0)
10

(4 Records with [Line] values 1, 2, 3, 4)
 
Back
Top