0

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.

Tomas
  • 181
  • 2
  • 10

1 Answers1

0

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.

Alan Schofield
  • 19,839
  • 3
  • 22
  • 35
  • That still says "Page 1 of 1" on every page after you export it to word – Tomas Oct 04 '22 at 11:58
  • Apologies, I did not export it, it must be an issue with the WORD renderer I guess. – Alan Schofield Oct 04 '22 at 16:19
  • and irritatingly, it works fine for PDF. Sounds like one you might need to raise with MS (good luck with that!) although it's probably listed under some 'feature' list somewhere on the MS website – Alan Schofield Oct 04 '22 at 16:24
  • What I found in Microsofts documentation for exporting paginated reports to Word "However, when a page footer or page header contains a complex expression that evaluates to different values on different pages of a report, the same value might display on all report pages." and "This occurs because Word renderer parses the report for fields related to pagination such as PageNumber and TotalPages and handles only simple reference, not calls to a function." So I guess that what I'm trying to do is technically impossible. – Tomas Oct 05 '22 at 07:28
  • Sometime the simplest thing in SSRS turn out to be the hardest! The only other things I can think of, if you report is a simple design, would be to add grouping to group your report by the contents for each page, then emulate the header contents in the group header row(s). Alternatively, you could use a subreport for each full page and pass the page number into the sub report as a parameter, then you could use that anywhere in you report. – Alan Schofield Oct 05 '22 at 08:38
  • Well that's an idea but unfortunately my report is basically 3 text boxes that can either be a few words or up to multiple pages long – Tomas Oct 05 '22 at 10:39