Alex
Alex

Reputation: 283

Microsoft Access Report - How to cycle through all pages of a report in print view?

I have a report that lists business names and the details of that business. Each business is typically on one page of the report in print preview.

I've managed to create some code that grabs all of the business names and the current page number that they are on and then adds them to a table(BusinessPage). I have placed this code in the 'On Print' section of the report.

Once I cycle through the report, all of the business names and their pages are added to the table (BusinessPage).

The index page then displays the corresponding page numbers for those particular businesses.

Now this works reasonably well, the only problem is: I have to cycle through each page of the report before the index page displays anything (This is because the table is only populated when the page 'On Print' code is activated. Page has to be viewed first before any information is added to the table).

My question is, is there a piece of VBA code that I can use to cycle through all of the pages of a report and then back again? If I can achieve this, it means it will return you to the start of the report and display all of the pages on the index page correctly because the report has already been cycled through.

Upvotes: 0

Views: 1056

Answers (1)

Andre
Andre

Reputation: 27634

The solution was to move the code from On Print to On Format.

On Print is only executed when a page is actually printed or previewed.

On Format is executed when the pages are prepared, e.g. by going to the last page in print preview. Or if the page footer contains [Pages]: to calculate the total number of pages, all pages must be prepared, so the code is executed too.

Upvotes: 1

Related Questions