Dig Me Out (Resetting Report Page Numbers)
Chris hasn't gotten a chance to update his Sleazy Hacks Weblog so I thought I would post this in the meantime.
Resetting the page number in a report isn’t natively supported in Reporting Services, but there is a partial workaround.
First, add this goes in Report code block (you can do this via the Report Properties dialog in VS)
Shared offset As Integer
Public Function GetPN(reset As Boolean, pagenumber As Integer) As Integer
If reset
offset = pagenumber - 1
End If
Return pagenumber - offset
End Function
Then, add a textbox in the page footer or header with the following expression:
="Page " & Code.GetPN(Not(ReportItems!tag.Value Is Nothing),Globals!PageNumber)
The texbox named “tag” is any textbox in the group header. Make sure the group header is NOT marked to repeat on each page, otherwise you’ll get a reset on each page.
Note: Since the offset must be shared (so that this will work across multiple callbacks to the server), if more than one person runs the report at the same time they’ll smash each other. So unless this is only ever going to be run as a subscription, you’d need to modify the offset to be a hashtable based on username. If the same user runs the report more than once at the same time, they’d screw up their page numbers, but that’s probably not worth worrying about.
Comments
- Anonymous
September 20, 2005
I can't believe it is this hard. Thanks for this information as I couldn't find out how to do this anywhere.
Now, I need to suppress the footer on every page except for the last page for the group. Any ideas on that one?
Thanks! - Anonymous
March 10, 2006
Is there anything similiar for resetting page numbers for subreports? - Anonymous
May 24, 2006
This code gives error at the page header / footer level.
I am using sql 2005 reporting services.
I even used Brian Welcker's Weblog but that also gave error.
Is there any other way to reset the page numbers at the group data level in sql 2005 reporting services. I need for my batch job.
Thanks - Anonymous
July 17, 2006
I want to use the total page count in the report body. Can you help me by writing its vb code or anything else useful? Thanks. - Anonymous
October 20, 2006
The comment has been removed - Anonymous
November 16, 2006
I have this working mostly in my report with the following exception:Body of the report prints but in the group footer there is a sub report that prints the notes. If this goes onto page # 2, the Page header still shows Page # 1. Any ideas on this one?Thanks - Anonymous
December 20, 2006
This is all fine and wonderful, but I'm getting a blank page printing in front of every subreport - for two subreports which span seven pages, I'm getting seven content pages and two blank ones with page numbers on the bottom.I know this is caused by the header printing in front of the subreport, but how do you get rid of it? Setting the header row's visibility to false makes the above code not work... - Anonymous
May 17, 2007
Is there a way to do reset the page range? So, if I have three invoices totalling 20 pages, it would be:Invoice 1: Page x of 10Invoice 2: Page x of 5Invoice 3: Page x of 10So, is there a way to get a total page count for a specific group? - Anonymous
June 25, 2007
The report I was working on required that the header for the group be shown for every page. So, after trying everything I said “Let’s group on the row number!” If we know how many rows are on a page we can calculate the page number and force a page break! For example you group by the customer ID and add a second grouping on the row number.Group 1 Expression=Fields!CustomerID.ValueGroup 2 Expression=(RowNumber("table1_Group1") - 1) 10 + 1On the group properties set “Page break at end” to TrueThis gives us 10 records on a page. If we need to display the page number and total number of pages for this group we can use this expression in the group 2 header. = “Page “ + (RowNumber("table1_Group1") - 1) 10 + 1 & " of " & ((Count( Fields!CustomerID.Value, "table1_Group1" )-1) 10 + 1)