|[ Team LiB ]|
Recipe 3.5 Create a Page-Range Indicator on Each Page
You're creating a report that contains a large number of items. To make it easier to see the range of items on each page, you'd like to create a page-range indicator. This would show the first and last items on the page, as in a telephone book. Is there a way to do this?
The answer to your question is a qualified yes. You can create such a page-range indicator, but placing it anywhere but in the page footer is difficult. Although you can place it in the page header, the method to do so is quite complex and is the subject of a topic in the Microsoft Access Solutions database (SOLUTIONS.MDB), which shipped with Access 95 and Access 97. You can also download an Access 2000 version of this very useful sample database, called Solutions9.mdb. Search for that name at http://msdn.microsoft.com to find the download.
Because Access prints documents from top to bottom, by the time you know the last item on the page it's too late to print it at the top of the page. The Solutions database workaround involves forcing the report to format itself twice, capturing the page ranges for all the pages during the first pass and storing the values in an array. When it makes the second pass, you supply the values from the array. That solution requires VBA and is cumbersome. The solution we present here focuses on a simpler method, placing the information you need in the page footer. If you can live with that placement, this solution is straightforward.
To create a page-range indicator on your own reports, follow these steps:
To view an example of this solution, load the rptPageRange report from 03-05.MDB in preview view (see Figure 3-11). You'll see, at the bottom of each page, a listing of the items printed on that page.
The technique presented in this solution is based on the fact that when Access prints the page header (or the report header or a group header), it gives you access to the row of data it's about to print. The same goes for footers, in reverse—there you have access to the row of data that's just been printed.
When you call the event procedure from the Format event of the page header, you place the data from the page's first row into the hidden text box, txtFirstItem. The data in that text box doesn't change until you again format the page. When Access gets to the bottom of the page and attempts to print the page footer, it calculates the value of the text box you've placed there. That text box retrieves the value you previously stored in txtFirstItem and combines it with the data from the last row that printed on the page to create the page-range indicator.
Though simple, this method does have a few limitations:
|[ Team LiB ]|