How to display result of query (sum of a field)

C

Chris Nebinger

The concept is right, you just need a little bit more:


strSQL = "Select Sum(Amount) As TotalSum from
tblGMISDrawdown where BlockGrantIntID = " &
Me.cboSelectBlockGrant.Column(0)
'Okay, no open the Recordset:
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
'The results can be accessed by using rst("FieldName")
strResult = rst("TotalSum")
Debug.Print " Total is " & rst("TotalSum")


Chris Nebinger
-----Original Message-----
Hi,
I need to have the sum of a query first set in a variable and then to display it.
I got the following code which is not working as I believe, my concept is not
correct. I am looking for any help on this. Thanks in advance.

Dim db As DATABASE
Dim rst As Recordset
Dim strSQL As String
Dim strResult As String

Set db = CurrentDb

strSQL = "Select Sum(Amount) As TotalSum from
tblGMISDrawdown where BlockGrantIntID = " &
Me.cboSelectBlockGrant.Column(0)
 
G

Guest

Thanks a lot. It was indeed a great help to me.

Chris Nebinger said:
The concept is right, you just need a little bit more:


strSQL = "Select Sum(Amount) As TotalSum from
tblGMISDrawdown where BlockGrantIntID = " &
Me.cboSelectBlockGrant.Column(0)
'Okay, no open the Recordset:
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
'The results can be accessed by using rst("FieldName")
strResult = rst("TotalSum")
Debug.Print " Total is " & rst("TotalSum")


Chris Nebinger

tblGMISDrawdown where BlockGrantIntID = " &
Me.cboSelectBlockGrant.Column(0)
 

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