Need Help With Loop . .

Evagrius

Registered User.
Local time
Today, 16:13
Joined
Jul 10, 2010
Messages
170
Hi,

I can't figure out what I am doing wrong here. The ICounter part works, but the MySum part sums the same exact number, not the aggregate of the records for that field. I would be grateful for any help.


Code:
Dim MyRecordset As DAO.Recordset
Set MyRecordset = Me.RecordsetClone
Dim i As Long, iCounter As Long

Dim MySum As Long
 
 
Rem START AT FIRST RECORD
MyRecordset.MoveFirst
 
    Do Until MyRecordset.EOF
        If MyRecordset![Building NO] = Me.Building_NO Then
        iCounter = iCounter + 1
        MySum = MySum + Me.Order_Amount
      End If

        MyRecordset.MoveNext
    Loop
 
Need a little more info here. But I think you may be having issues with the similar problem before (using control name instead of field name). Shouldn't it be:

MySum = MySum + MyRecordset![Order Amount]
 
RIGHT! That worked perfect! I should have referenced the recordset clone! You are awesome Bob!! The recordsetclone was the one that was moving forward, not the actual form - that's why it kept adding the same number, right? Thank you Bob!
 

Users who are viewing this thread

Back
Top Bottom