Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add cells in a datagrid

Posted on 2009-07-10
17
Medium Priority
?
286 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…
Suggested Courses

618 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