Obtain report page count with out previewing the report.

D

Del LaBo

I am working on a database to track specific shipments. Each one of
these shipments is required to have one of two reports attached to the
shipment before it leaves our facility. Each of the two reports
requires a special form be loaded into the printer. These reports can
range from 1 to many pages depending on the items being shipped.

After the user enters the shipment details they click a "Submit
Shipment / Print Report" button.
The database then determines which of the two reports is required
based on data entered by the user.
The database then presents the user with an input box asking how many
copies of the report they want printed.
Once the user inputs the number of copies they want the database
presents a message box that reminds the user to place the proper form
paper in the printer. When the user clicks OK on the message box the
database prints the reports.

The problem is the user doesn't know how many pieces of the form paper
to place in the printer because they don't know how many pages the
report actually is
Example: If the user wanted 5 copies of the report and the report is
only one page they would need to insert 5 sheets into the printer but
if the report was 2 pages they'd need to insert 10 sheets into the
printer.

What I need help with is how to determine the number of pages is in
the report with out displaying / previeiwng the report.

I would like to know if it is possible via VB to determine the number
of pages in the report. I could then take the number of pages and
multiply that by the number of copies the user wanted printed and put
the results in my message box so it would read something like "Place
10 sheets of form one into the printer, press OK to print."

Thank you!
 
J

John Spencer

You can try the following UNTESTED code to get the page count. It MIGHT
require you to have a control on the report with its source set to =Pages.
The control could be invisible. Or if you already have Pages x of n Pages on
the report then you would not need to worry about it.

Public Function fGetPageCount(strReportName)

'Open the report in invisible mode (hidden)
DoCmd.OpenReport strReportName, acViewPreview, , , acHidden

'Get the page count
fGetPageCount = Reports(strReportName).Pages

'Close the report so you can reopen it for the user
DoCmd.Close acReport, strReportName, acSaveNo

End Function

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
D

Del LaBo

Thanks John,
That worked perfectly!

You can try the following UNTESTED code to get the page count.  It MIGHT
require you to have a control on the report with its source set to =Pages.
The control could be invisible.  Or if you already have Pages x of n Pages on
the report then you would not need to worry about it.

Public Function fGetPageCount(strReportName)

    'Open the report in invisible mode (hidden)
    DoCmd.OpenReport strReportName, acViewPreview, , , acHidden

    'Get the page count
    fGetPageCount = Reports(strReportName).Pages

    'Close the report so you can reopen it for the user
    DoCmd.Close acReport, strReportName, acSaveNo

End Function

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County










- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top