Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I return the report pagecount before printing the report....

Status
Not open for further replies.

PerryG

Programmer
Aug 15, 2000
75
0
0
US
and give the user the option to cancel after they see the report may be 1300 pages long.
 
You will need to add a Text Box to any Reports that you use this on.

Set the Control Source of this Text Box:
=Pages

Set the Visible property to:
No

Paste the following into the Page event of the Report:
Dim strPrint As String
Static intCounter As Integer
intCounter = intCounter + 1
If intCounter = 1 Then
strPrint = MsgBox("There are " & Me.Pages & " Pages in this Report. Do you want to Print them?", _
vbYesNo + vbQuestion, "Print Confirmation")
If strPrint = vbNo Then
DoCmd.Close acReport, Me.Name
End If
End If

Bill
 
This works great on 2000, but now I need to migrate the db back to 97 and I keep getting the 2585 runtime error. Access 97 help files indicates the following:Syntax

Private Sub Report_Page( )

Remarks

You can't cancel the Page event.

Naturally, time is short.....

Any help greatly appreciated.

PerryG
 
Hi PerryG,

This was quite an interesting one, I noticed this doesn't happen when opening the report in print preview, so firstly the report is opened in preview (not visible because of the message box) if yes is selected prints the report.

Place this in the Declarations Section of a Module:
Public gPrintReport As Boolean

Place in the On Page event of the Report:
Dim strPrint As String
Static intCounter As Integer
If gPrintReport = False Then
intCounter = intCounter + 1
If intCounter = 1 Then
strPrint = MsgBox("There are " & Me.Pages & " Pages in this Report. Do you want to Print them?", _
vbYesNo + vbQuestion, "Print Confirmation")
If strPrint = vbYes Then
gPrintReport = True
End If
DoCmd.Close acReport, Me.Name
End If
End If

Replace the existing OpenReport code on your Form with:
gPrintReport = False
DoCmd.OpenReport "YourReportName", acViewPreview
If gPrintReport = True Then
DoCmd.OpenReport "YourReportName"
End If

Replace the red text with your report name.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top