urgent - sum all rows for an unknown number of fields

sure and thank you
i see you're unbanned)))))))))))))))



Code:
Dim dbs As Database, tdf As TableDef
Dim fld As Field
Dim rst As DAO.Recordset
Dim i As Integer
Dim RowSum As Double


Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Mailboxes", dbOpenSnapshot)

i = 2

With rst
rst.MoveLast
rst.MoveFirst
        Do While Not rst.EOF
        i = 2
            Do While i < (rst.Fields.Count - 1)
            Set fld = rst.Fields(i)
                If Not IsNull(fld.Value) Then
                RowSum = RowSum + fld.Value
                Else
                RowSum = RowSum
                End If
            i = i + 1
            Loop
            
            rst.MoveNext
            




---------------------------------------------      
.Edit
.Fields("GrandTotal").Value = RowSum
.Update
---------------------------------------------        
        
        
        RowSum = 0
        Loop
        rst.Close
End With



everything works except this and i don't have the dashes in the code of course

---------------------------------------------
.Edit
.Fields("GrandTotal").Value = RowSum
.Update
---------------------------------------------
 
Try this instead (I've removed the extraneous stuff AND you were opening the table as a SNAPSHOT which can't be updated.):

Code:
   Dim dbs As DAO.Database
    Dim fld As DAO.Field
    Dim rst As DAO.Recordset
    Dim i As Integer
    Dim RowSum As Double


    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("Mailboxes")

    i = 2


    Do While Not rst.EOF
        i = 2
        Do While i < (rst.Fields.Count - 1)
            Set fld = rst.Fields(i)
            RowSum = RowSum + Nz(fld.Value, 0)
            i = i + 1
        Loop
        rst.Edit
        rst.Fields("GrandTotal").Value = RowSum
        rst.Update
        rst.MoveNext

        RowSum = 0
    Loop
    rst.Close
    Set rst = Nothing
 
Try this instead (I've removed the extraneous stuff AND you were opening the table as a SNAPSHOT which can't be updated.):

Code:
   Dim dbs As DAO.Database
    Dim fld As DAO.Field
    Dim rst As DAO.Recordset
    Dim i As Integer
    Dim RowSum As Double


    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("Mailboxes")

    i = 2


    Do While Not rst.EOF
        i = 2
        Do While i < (rst.Fields.Count - 1)
            Set fld = rst.Fields(i)
            RowSum = RowSum + Nz(fld.Value, 0)
            i = i + 1
        Loop
        rst.Edit
        rst.Fields("GrandTotal").Value = RowSum
        rst.Update
        rst.MoveNext

        RowSum = 0
    Loop
    rst.Close
    Set rst = Nothing

thank you!!!!!!!!!!!!!!!!!!!!!

and the banned thingie wasn't funny, my heart dropped, you bail me out all the time and you've helped everyone here at least 10 times each, i just couldn't believe you got banned. i thought maybe someone smoked something
 
and the banned thingie wasn't funny,
Sorry, I have a twisted sense of humour.


crazysmile.jpg
 
Sorry, I have a twisted sense of humour.


crazysmile.jpg

apology not accepted, i grew gray hair when i saw that))))))))))))))))))

i was joking about the whole thing by the way, i mean i really was shocked when i saw it, but my post was supposed to be humorous
 
Bob, can i take advantage of you one more time

what's the best way to do the bottom totals?
 
never mind, i got it, thank you so much for your help, i wouldn't get this one without you
 

Users who are viewing this thread

Back
Top Bottom