Link to home
Start Free TrialLog in
Avatar of Everymancomputers
Everymancomputers

asked on

Calculate total value of a datagrid column vb6

Hi,

I'm trying to calculate the total number value of a column in a data grid and display that value in a text box using Visual Basic 6. but I'm not sure on how to achieve this ?
ASKER CERTIFIED SOLUTION
Avatar of esolve
esolve
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robberbaron (robr)
if you are using the DataGrid ( and not the MSFlexGrid), I think you would be better off doing an SQL summation on the desired column, not trying to add up cells of the displayed data.  
(ive never used DataGrid as found bound controls too troublesome.  the "approxCount" property raises concerns !)
<calculate the total number value>
Lets be clear...
Are you wanting to "Count" the values (Number or Text)  or "Add" them (Number Only)

Does VB6 not allow Aggregate Functions?

txtYourTextBox=Dcount("YourField","YourTable")
...for a count

Or this for a sum:
txtYourTextBox=Dsum("YourField","YourTable")

JeffCoachman
vb6 does not include Dsum

but should use a dbCommand object.

http://msdn.microsoft.com/en-us/library/ms675023(v=VS.85).aspx

commandText = "SELECT SUM(myColumnName) FROM myDataTable"

Set recordset = connection.Execute (CommandText, RecordsAffected, Options)
robberbaron
Thanks
It's been a long time for me since last using VB6...
I just did not remember...
:-(

Jeff