Solved

Add cells in a datagrid

Posted on 2009-07-10
17
273 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
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

691 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