PDA

Click to See Complete Forum and Search --> : total in vb


Sked
Oct 17th, 1999, 09:04 AM
hi there,

i'm quite new to database programming in VB and im wondering whats the best way to total records. I have a database with like a hundred or so numeric fields, and i want to get a single record containg the totals of those fields. Right now i'm doing something like this: For X = 0 To 138
Set temp = dbs.OpenRecordset("select sum(" + mainrec.Fields(X).Name + ") as s from mdbtemp where year = '" + year + "'")
recs.Fields(X).Value = temp.Fields("s").Value
Next

which i believe is terrible and inefficient.
is there any easier way to do this like the "total" command in foxpro? thanks in advance.

chem1
Oct 17th, 1999, 11:25 AM
why don,t you use the SUM Command of SQL.Also you can put the contents of an entire column in a loop and total them.Another way is to total the record in the Data Report rather than anywhere else because that is where it is needed.There u can use the sum function.
Hope this helps
Kamran.