Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum Field from Recordset

Status
Not open for further replies.

jpinto

Technical User
Dec 12, 2003
75
PT
Hello,

I've a recordset displayed on a Data grid. I'm trying to sum the values of a field so that I can have the total sum of the entire recordset displayed on a field. I've tryed the follow:

VendaTable.Recordset.MoveFirst
Do Until VendaTable.Recordset.EOF
QtdTotal = QtdTotal + VendaTable.Recordset.qtd
VendaTable.Recordset.MoveNext
Loop

I'm receiving the error:

Run-time error "13": type mismatch

Can annyone help me please.

Thanks,

João
 
Is the field called qtd??

if so you should do this

QtdTotal = QtdTotal + VendaTable.Recordset.Fields("qtd")

If this isn't the problem, then chances are that QtdTotal and the field qtd are different data types.
What data type is QtdTotal? And what datatype is qtd in your database?

Transcend
[gorgeous]
 
QtdTotal = QtdTotal + val(VendaTable.Recordset.qtd). If qtd is your Currency field, however, If you are trying to accumulate the result in a text field on the form named QtdTotal then QtdTotal is actually a text field and you may have to accumulate the total in a Field that dimmed double or something like that, then place it in the text box.
 
Use the sum aggregate function

SELECT SUM(qtd) AS SomeField
FROM YourTable

and my guess is that your hitting a record with a NULL value and that is why your getting the error.

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I've already found the error!

I was trying to sum the value of the field to a null value. I tryed to do the follow and it works fine:

VendaTable.Recordset.MoveFirst

QtdTotal = VendaTable.Recordset.qtd

VendaTable.Recordset.MoveNext

Do Until VendaTable.Recordset.EOF
QtdTotal = QtdTotal + VendaTable.Recordset.qtd
VendaTable.Recordset.MoveNext
Loop

Thanks anyway for your hints.

João
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top