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
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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.