Show a Footer Only on the Last Page?
Imagine you have to create a report, for example a Document, and there’s certain information, like for example Sales Conditions, that only need to be printed on the footer of the last page. How do you do that in RDLC?
A good thing is always to investigate if there’s a property that you can use. In this case the properties of a header and footer that could help us are: PrintOnFirstPage and PrintOnLastPage. But actually, these two properties allow us to NOT print something on the First and/or Last page, and what we want is the other way around. So, bad luck, these properties will not help us.
Then let’s have a look at the Globals collection. Here we have two interesting Globals:
- Globals!PageNumber
- Globals!TotalPages
So, let’s try to use them.
When you use these in a textbox in the body of a report you will get an error:
So adding a textbox to the body of the report and determining via an expression if we are on the last page and then showing/hiding it is not an option. Why would we do this you might think. If you place something at the bottom of the Body it is automatically shown only on the last page, no? Well, in Dynamics NAV Document reports, the Body contains a List, putting it in the List would make it appear on every page and putting it below the List is not an option, because it needs to be shown on the last page, for everydocument.
No problem, let’s put it where it’s allowed, for example the Footer.
To be able to show a field in the dataset on a Footer (or Header) we will need to declare a Variable, a Set function and a Get function:
Shared LastPageInfo as Object Public Function GetLastPageInfo() as Object Return Cstr(LastPageInfo) End Function
Public Function SetLastPageInfo(NewData as Object) If NewData > "" Then LastPageInfo = NewData End If End Function
Now we will create a Layout:
The textbox in the Footer is inside a Rectangle and in the Hidden property of the Rectangle we can set the following expression:
And voila the result:
Here you can download the example: InfoOnLastPage v1
This was originally posted here.
*This post is locked for comments