OK so just learning here... getting past a few early hurdles will really help. Easy one for you pros!
In Table [QueryTest] there are 20 rows of data. I want to add each of the 20 values in field [MarketValueImpact] together to get one cumulative value, using a loop.
The code breaks at the bold line, specifically where the ???'s are. If I use a number there it works, if I use a field name or variable it does not.
Any help is appreciated
____________________________________
Public Sub OpenRecordset()
Dim i As Integer
Dim ropen As Integer
Dim impact As Integer
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("QueryTest")
ropen = rs("MarketValImpact")
impact = rs("MarketValImpact")
For i = 0 To rs.RecordCount - 1
impact = rs("MarketValImpact")
ropen = ropen + impact
Debug.Print (ropen)
rs.MoveNext
Next i
rs.Close
Set rs = Nothing
db.Close
End Sub
In Table [QueryTest] there are 20 rows of data. I want to add each of the 20 values in field [MarketValueImpact] together to get one cumulative value, using a loop.
The code breaks at the bold line, specifically where the ???'s are. If I use a number there it works, if I use a field name or variable it does not.
Any help is appreciated
____________________________________
Public Sub OpenRecordset()
Dim i As Integer
Dim ropen As Integer
Dim impact As Integer
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("QueryTest")
ropen = rs("MarketValImpact")
impact = rs("MarketValImpact")
For i = 0 To rs.RecordCount - 1
impact = rs("MarketValImpact")
ropen = ropen + impact
Debug.Print (ropen)
rs.MoveNext
Next i
rs.Close
Set rs = Nothing
db.Close
End Sub