SSRS creating different headers for different pages with page numbers and total number of pages

536 Views Asked by At

I need to create a report and export it to .docx that shows the page number and total number of pages in the first page header (e.g. "1 of 5") and only show the page number in the header for all other pages (e.g. "2", "3").

What I've tried so far

  1. Creating 2 text boxes in the header and setting their visibility to "=Globals!PageNumber=1" and "=not Globals!PageNumber=1" or "=Globals!OverallPageNumber=1" and "=not Globals!OverallPageNumber=1". Both text boxes either exist on all pages or don't exist at all.

  2. Setting the header to not print on the first page, adding only the page number to the header and adding a text box with the expression code.PageNumber & " of " & code.TotalPages to the top of the report body and adding

Function PageNumber() As String
Return Me.Report.Globals!PageNumber.ToString()
End Function

Function TotalPages() As String
Return Me.Report.Globals!TotalPages.ToString()
End Function

to report code, because you can't use global variables in report body. But the text box in the body always shows "1 of 1" no matter how many pages there are.

Is there something I did wrong in my attempts that I don;t understand?

Is there another way of achieving the result I need?

I'm not sure which version of ssrs I'm using but solutions that work with any version would help me a lot.

1

There are 1 best solutions below

6
Alan Schofield On

Add your header then add a textbox to the header and set the expression to this.

="Page " & 
Globals!PageNumber & 
IIF(Globals!PageNumber = 1, 
    " of " & Globals!TotalPages,
    "")

This will show "Page 1 of 5" on the first page and then just "Page 2" etc on subsequent pages.