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

Creating Incrementing Counters in RS

Report Formatting

Creating Incrementing Counters in RS

by  Catadmin  Posted    (Edited  )
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!

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top