get report total pages before printing

supmktg

Registered User.
Local time
, 21:26
Joined
Mar 25, 2002
Messages
360
I have a report that can be very very long, and I want to warn the user before it gets sent to the printer. Right now, I'm opening the report in preview mode and then bringing up the print dialog in code. I'd like to add a message box with the number of total pages before the print dialog comes up.

Code:
             DoCmd.OpenReport "PMDetailAllTrades", acViewPreview
'add msgbox "this report is 'nnn' pages long"
             DoCmd.RunCommand acCmdPrint
             DoCmd.Close acReport, "PMDetailAllTrades"

How do I get the total number of pages?

Thanks,

Sup
 
Try this ,Access 2002 or later

PHP:
Dim stDocName as String
stDocName ="Name of your Report"

  DoCmd.OpenReport stDocName, acViewPreview, , , acHidden
      If MsgBox("There are " & Reports(stDocName).Pages & " pages in this report, Are you sure want to print it?", vbOKCancel + vbQuestion, "Confirm Print") = vbOK Then
         DoCmd.OpenReport stDocName, acViewNormal, , , acWindowNormal
  Else
      DoCmd.Close acReport, stDocName
  End If
 
Last edited:
...actually just taking that one step further you could show the message box only if the number of pages exceeds a set value.

PHP:
Dim stDocName as String 
stDocName ="Name of your Report" 

DoCmd.OpenReport stDocName, acViewPreview, , , acHidden
      If Reports(stDocName).Pages > 3 Then
            If MsgBox("There are " & Reports(stDocName).Pages & " pages in this report, Are you sure want to print it?", vbOKCancel + vbQuestion, "Confirm Print") = vbOK Then
                DoCmd.OpenReport stDocName, acViewNormal, , , acWindowNormal
            Else
            DoCmd.Close acReport, stDocName
            End If
      Else
       DoCmd.OpenReport stDocName, acViewNormal, , , acWindowNormal
     End If
 
Last edited:
That's exactly what I needed! I just couldn't get the number of pages.

Thank you VERY MUCH,

Sup
 
hey guys!

I put the following code in the report's load event and I always get 0 for:

Code:
MsgBox Reports("my_report").Pages

Do I need to set something to get the report total pages?
 
itazev,

I believe you need to open the report in order to get a page count.
This should work for you:
Code:
Dim stDocName as String 
stDocName ="Name of your Report" 

DoCmd.OpenReport stDocName, acViewPreview, , , acHidden
msgbox  Reports(stDocName).Pages

Hth,
Sup
 
access 2000?

I happen to work for one of those companies who knows how important it is to keep their systems up-to-date...NOT!

Can anyone tell me what the same code would be in Access 2000?

Namely, there are too many arguments in the "DoCmd.OpenReport" lines (so I don't know how to hide the report), and I get a message box saying that "Reports(stDocName).Pages" is an expression that is an invalid reference to the property Pages.

Any help would be much appreciated.
 
Got it working in Access 2000

I happened to get it to work in Access 2000. Here's the code:

Code:
    Dim stDocName As String
    stDocName = "(YourReportName)"

    'Open and hide the report
    DoCmd.OpenReport stDocName, acPreview
    Reports(stDocName).Visible = False
                
    'Warn the user if there are more than 10 pages in report
    If Reports(stDocName).Pages > 10 Then
        If MsgBox("There are " & Reports(stDocName).Pages & _
            " pages in this report, are you sure want to print it?", _
            vbYesNo + vbQuestion, "Confirm Print") = vbYes Then
            DoCmd.OpenReport stDocName, acViewNormal
        Else:
            DoCmd.Close acReport, stDocName
        End If
    Else
        DoCmd.OpenReport stDocName, acNormal
    End If
 
Last edited:

Users who are viewing this thread

Back
Top Bottom