Solved

Add cells in a datagrid

Posted on 2009-07-10
17
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 105
vbModal 12 73
converting visio 2010 to powerpoint 2010  - formatting issues 5 122
transition to visual .net from vb6 5 79
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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