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

  • Thread starter Thread starter Chris Nebinger
  • Start date Start date
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)
 
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)
 
Back
Top