Select Sum (1 Viewer)

Geirr

Registered User.
Local time
Today, 23:55
Joined
Apr 13, 2012
Messages
36
Hi.

I'm little stuck here, and I hope I could get some input..

On a pushbutton click event, I have the following code:
Private Sub cmdTest1_Click()

Dim rsCable As ADODB.Recordset
Set rsCable = New ADODB.Recordset
rsCable.ActiveConnection = CurrentProject.Connection

rsCable.Open "SELECT Sum(Cable.Meter) AS SumAvMeter FROM Cable"

Me.txtResult = 'Here I would like the result of the query above
End Sub

I know this is wrong, but I just don't know how to use a simplest way to sumarize all value in the table field Cable.Meter above. Today I'm using a Do While loop, sumarizing all values, but in more than 10000 records, this takes time...

So the question are, how can I use Select Sum in this scenario?

- Geirr.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:55
Joined
Feb 19, 2013
Messages
16,553
don't understand the question since your sql will return just one value. but you could use

Me.txtResult =rsCable!SumAvMeter

or don't bother with a recordset, just use the dsum function

me.txtResult=dsum("Meter","Cable")
 

Geirr

Registered User.
Local time
Today, 23:55
Joined
Apr 13, 2012
Messages
36
Thanks for your reply.
I believe you understod the question because your solution with
Me.txtResult =rsCable!SumAvMeter
worked perfectly. I just got a totally block on this solution, so simpla as it is...:banghead:


Thanks again.
-Geirr
 

Users who are viewing this thread

Top Bottom