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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Problem - (Variable Type)

Status
Not open for further replies.

fredk

Technical User
Jul 26, 2001
708
US
I am hoping that someone can take a look at the following code and let me know where I am going wrong - When I run this code I get a


Dim intX As Integer
Dim lngRowTotal As Long

If Me.PrintCount = 1 Then
lngRowTotal = 0

For intX = 2 To intColumnCount
' Starting at column 2 (first text box with crosstab value),
' compute total for current row in detail section.
lngRowTotal = lngRowTotal + Me("Col" + Format(intX))
' Add crosstab value to total for current column.
lngRgColumnTotal(intX) = lngRgColumnTotal(intX) + _
Me("Col" + Format$(intX))
Next intX
' Place row total in text box in detail section.
Me("Col" + Format$(intColumnCount + 1)) = lngRowTotal
' Add row total for current row to grand total.
lngReportTotal = lngReportTotal + lngRowTotal
End If
End Sub

When I run this code I get a type mismatch error on this line:

lngRowTotal = lngRowTotal + Me("Col" + Format(intX))

Any help would be greatly appreciated!!!

Thanks


 
the brief answer is that the format function needs additional arg, as to HOW to format the var.

Look into Help and the several Samples which are part of the Ms. A system. Doing totals over groups and over all are readily explained, and several examples demonstrate the easier approach to doing rowset sums on reports and/or queries.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
I think you need format(intX, "00")

0 00
1 01
2 02

10 10

20 20

would be the result.

rollie@bwsys.net
 
If I'm not mistaken, the code comes from MS. A Solutions sample database and shows how to create a cross-tab report with dynamic column headings.

Dan
[pipe]
 
Dan, you hit the nail on the head!!!- I took this example from the Northwind database. I figure the best way to learn is to use the help and the examples. Also, Tek-Tips (of course)


I find this an excellant format for receiving assistance. I also try to help when I can although my experience is limited.

As far as my problem, I created my own form to use with the example code- When I copied over the form from the example and made my modifications, it worked.

In looking in the help file for the format function I would agree that it seems thats where the problem lies. However, it seems to work in the Northwind database.

Rollie Dan and Michael, thanks for your assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top