How do I get a column total from datagrid?

atsivel
atsivel used Ask the Experts™
on
Hi,
I used the datagrid to list data from an Access table.
There is a contact hours column in the datagrid.  I want to be able to list the total contact hours in a text box at the bottom of the datagrid?  Is that possible?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Yes it is possible.

Dim intSum as Integer
Dim intLoop as Integer

'Lets suppose the Col no. to be 1
For intLoop = 0 to grid.rows-1
  intSum = intSum + cint(grid.TextMatrix(intLoop,1)  
Next intLoop

msgbox intSum

In the above code we are looping through each row of the grid and getting the value of the fields below Col no. 1.
You can change the col no. in TextMatrix parameter accoring to your code.

In case you have a Fixed row in your grid then start the loop with 1 instead of 0.
Author of the Year 2009

Commented:
Hi atsivel,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Sethi's comment(s) as an answer.

atsivel, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.
==========
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial