Solved

Add cells in a datagrid

Posted on 2009-07-10
17
258 Views
Last Modified: 2012-05-07
I have a datagrid in vb6.  I have columns 10 through 35 that should have numbers in them.  From the datagrid I want them to autoTotal into column 36.  Is there a way to do this.  Its kind of simalar to what Microsoft Excel does with the SUM function.
0
Comment
Question by:al4629740
  • 9
  • 8
17 Comments
 
LVL 9

Assisted Solution

by:wellhole
wellhole earned 500 total points
ID: 24826682
Add a column to your datasource, then loop through it and run a sum and put the result into the column you added.

table.Columns.Add("mysum")

for each row in table
  for i = 10 to 35
    table("mysum") += row(i)
  next
next
0
 

Author Comment

by:al4629740
ID: 24826730
Is that code for vb6?  The following line does not work

table("Total") += row(i)
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826733
oops...

row("mysum") += row(i)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:al4629740
ID: 24826747
Still no go..
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826764
And your problem is.......?
0
 

Author Comment

by:al4629740
ID: 24826814
Meaning your formula does not work.  Will this work?

For Each Row In Table
  For i = 10 To 35
    Row("Total") = Row("Total") + Row(i)
  Next
Next
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826837
You forgot Table.Rows in your first line.
0
 

Author Comment

by:al4629740
ID: 24826865
Could you show me what your talking about.  I am very novice to VB
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826886
It would be very helpful if you provided the error messages instead of just saying "it doesn't work".
0
 

Author Comment

by:al4629740
ID: 24826919
Ok, originally you sent the code and it showed Expected:expression   Compile error on this line

table("mysum") += row(i)
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826929
Right. Now that you have the code below, what errors do you have now?

For Each Row In Table.Rows
  For i = 10 To 35
    Row("Total") = Row("Total") + Row(i)
  Next
Next
0
 

Author Comment

by:al4629740
ID: 24826944
Object required in the first line

For Each Row In Table.Rows
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826975
al, is your table variable called Table?
0
 

Accepted Solution

by:
al4629740 earned 0 total points
ID: 24827042
ha, good catch.  I changed it to the following:

For Each Row In DataGrid1.Row
  For i = 10 To 35
    Row("Total") = Row("Total") + Row(i)
  Next
Next

But I still get an error on the first line:

Compile error:
For Each may only iterate over a collection object or array

0
 
LVL 9

Expert Comment

by:wellhole
ID: 24827066
al, is your datagrid binding to a table or are you adding into the grid programmatically?
0
 

Author Comment

by:al4629740
ID: 24827094
Programmatically, as follows:

      rec.CursorType = adOpenDynamic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
      rec.Open esql, conn, , , adCmdText



     
        Set DataGrid1.DataSource = rec
0
 

Author Comment

by:al4629740
ID: 24828554
raised point value
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question