Recordset loop takes value only from first record

Television

Registered User.
Local time
Today, 04:48
Joined
May 15, 2013
Messages
31
Greetings again!

I have a following problem: I have a form in continuous mode. Users are supposed to filter data in it to their liking using inbuild filters in Access. After that there is a button that should calculate total weights in filtered records (at this point, I add more calculations once I have solved this issue). Code of button is as follows:
Code:
Private Sub btnCalculateWeight_Click()

    Dim rst As Recordset
    Dim weight As Long
    Dim material As Long
    Dim subtype As Long
    Dim locus As Long
    Dim tempweight As Long
    Dim totweight As Long
    Set rst = Me.RecordsetClone
    totweight = 0
    weight = 0
    If Not (rst.EOF And rst.BOF) Then
    rst.MoveFirst
        Do Until rst.EOF = True
            material = Me.MaterialID
            subtype = Me.SubtypeID
            locus = Me.LocusID
            If material = 1 Or material = 8 Then
                tempweight = PotteryWeights(locus, material, subtype)
                MsgBox (tempweight)
                weight = (tempweight + weight)
            Else
                tempweight = MaterialWeight
                MsgBox (tempweight)
                weight = (tempweight + weight)
            End If
            rst.MoveNext
        Loop
        totweight = weight
    Else
        MsgBox ("You have filtered to empty recordset!")
    End If
    MsgBox (totweight)
    rst.Close
    Set rst = Nothing
End Sub
Loop goes through recordset correct amount of times but for unknown reason takes value only from the first record and sums it N times where N is number of records in recordset. Recordset seems to be correctly assigned according to messageboxes I added to pinpoint problem. PotteryWeights is a custom function I made and it works properly. Could anyone tell me what is wrong with this code?

Thank you in advance!

Television
 
Inside your loop you only take values from Me (meaning what is visible on the form)
Not from your recordsetclone, rst
 
Inside your loop you only take values from Me (meaning what is visible on the form)
Not from your recordsetclone, rst

Thanks! Changed to this
Code:
tempweigh = rst.Fields("MaterialWeight")
and it works now.

Television
 

Users who are viewing this thread

Back
Top Bottom