INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Report Formatting

Creating Incrementing Counters in RS by Catadmin
Posted: 20 Jul 05

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 ESSENTIAL 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!


Back to Microsoft SQL Server: Reporting Services FAQ Index
Back to Microsoft SQL Server: Reporting Services Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close