I have a form with a DataGrid one Column is currency I need to show the total of that column in either a txtBox or in the StatusBar. Any idea how I can do this ?
Since I have a number of rows isn't there a way to loop thru the Currency Column only to get a Total for just that column ? The column will contain different numbers of rows depending on the recordset.
Unfortunately, in a DataGrid, the row property only works on visible rows - in other words, what you can see on the screen and not what was on the previous page or next page.
Use the underlying recordset object to calculate the sum:
dim rs as ADO.recordset
dim dSum as double
set rs = Data1.Recordset.Clone
rs.MoveFirst
Do until rs.eof
dSum =dSum + rs("TheFieldToSumOn"
loop
Try using a standar collection or array when you populate the data grid populate the collection or array as well then if you use a collection you can loop through and add the
Two problems.
1. Data1 is the data control object that the grid is bound to - not the grid control it self.
Either the grid is bound to a DC or a recordset. If a DC, then use the DC object; if a recordset, then use the recordset object name.
2. I forgot to add MoveNext. Otherwise you will have an endless loop - it was typed on the fly:
Do until rs.eof
dSum =dSum + rs("TheFieldToSumOn" rs.MoveNext
loop
i agree if your just going to clone it you should just use the recordset you already have. don't try and make it harder than it is! ----------------
Joe
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.