SQL SELECT SUM or DSUM ?

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 ?
 
V

Van T. Dinh

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top