views:

25

answers:

1

In MS Access reports, page counts can be displayed using a text box with the following:

= "Page " & Page & " of " & Pages & " Pages"

However, this is problematic for large reports, as Access cannot open the first page of the report in Preview until ALL pages have been formatted (so it knows the total number of pages).

Ideally, in Preview I'd only display "Page 123", but when the report is actually Printed, that would get replaced by "Page 123 of 456 Pages".

This is probably wishful thinking, but has anyone managed something like this?

+3  A: 

Access 2007 (You didn't indicate your version), has CurrentView property available through vba and you can change the control source of the page text box:

Private Sub Report_Open(Cancel As Integer)

 Select Case Me.CurrentView
      Case acCurViewDesign

      Case acCurViewPreview
          ' Page # Only
          Pages_TextBox.ControlSource = "Page" & Me.Page

      Case acCurViewReportBrowse

          ' Page # of #
          Pages_TextBox.ControlSource = "Page" & Me.Page & " of " & Me.Pages
      Case acCurViewLayout
               End Select
End Sub
Jeff O
Good suggestion. There are named constants for these states, and I'd tend to use them instead of literal values, since they save needing to add comments explaining what each value refers to.
David-W-Fenton
I finally found the constants and updated.
Jeff O
maxhugen
You may have to do this in the PageHeaderSection_Format. Not ideal, but it will fire when they print. Bad thing is it runs for each page.
Jeff O