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!

Using Counters in Reporting Services 2

Status
Not open for further replies.

Catadmin

Programmer
Oct 26, 2001
3,097
0
0
US
WHOOOHOOO!

With someone's help on the MS website, I finally figured out how to create variables and set them summable/countable. I'm posting here in the hopes I can save someone else the grief. @=)

Go to Report Properties -> Code tab. Then you have to create a series of functions (not DIM a variable) that will increment your counter, reset your counter and display your counter.

The basic syntax is as follows:

Code:
 --- Note: Public and Shared are ESSENTIALLY keywords
 --- without them, the code won't work throughout the whole
 --- report!!!

Public Shared <VariableName> as <datatype>
            -- For a counter, use INT
Public Shared Function <FunctionName>() as String
<VariableName> += 1  
       -- += is equivlant to the T-SQL "Set Num = Num + 1"
Return <VariableName>.ToString
      -- This is a select stmt that calls the function
     -- as a string returned variable

Return ""
     -- This can be used as an alternative to the above
     -- to return/display nothing.

END Function

Only use one of the two above Return statements. If you just want to display the variable (anywhere on your report), omit the increment portion of that code. If you want to Reset the variable, create a function that has a "<VariableName> = 0" and uses the blank Return statement.

I set my reset into the footer, set the increment into the header, didn't display it at all, but used the counter in a visibility property: IIF(Counter <= 1, False, True) to resolve my group header printing in the middle of the page problem.

I hope this helps someone. Let me know if you need clarification!



Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
Catadmin said:
Note: Public and Shared are ESSENTIALLY keywords

DOH! This should read "Note: Public and Shared are ESSENTIAL keywords", not Essentially.

Sorry about any confusion.




Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
Nice Catadmin - that's inventive !!

Rgds, Geoff

A file that big? It might be very useful. But now it is gone

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top