Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summing Column Data with Code????

Status
Not open for further replies.

DCBBB

IS-IT--Management
Aug 22, 2001
33
0
0
US
Can any anyone show me how to sum a column of data in VB on a report? I have a report (based off of a crosstab) using unbound columns which assigns the values to the text boxes at run time. This is done for flexibility and control reasons. So, I can't sum the usual way (assign a value in the control source of a text box in the footer i.e. =Sum([Value])). Can anyone help? Thanks!
D
 
If you are assigning the values at run-time, can't you just sum them up as you are assigning them, then assign that sum to a text box in the footer? Maybe I'm missing something.

Shanti
 
Shanti,
Thanks for responding!
The only thing you are missing is that I am a VB amatuer in over my head.
Here's what I have:

Dim intX As Integer
Dim ColumnTotal(1 To conTotalColumns) As Long
Const conTotalColumns = 12

For intX = 2 To intColumnCount 'Column 2 is where the actual data starts
ColumnTotal(intX) = ColumnTotal(intX) + Me("Col" + Format(intX))
Me("Tot" + Format(intX)) = ColumnTotal(intX)
Next intX

Where intColumnCount is the number of columns (can vary)
"Col" is the name of the unbound text boxes where I assign data to (col1, col2...)
"Tot" is the name for my unbound text boxes where I want my totals(tot1, tot2...)
With this code, the report total is giving me the last record in the column, not the total.
What am I doing wrong?!?! Thanks!
D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top