Ok, as usual haste makes waste. The previously posted code does not work!
Here is the code that actually works:
Option Compare Database
Public FrmtCnt As Integer
Private Sub Report_Close()
If FrmtCnt > 3 Then
MsgBox vbCr & "This Report Contains Way To Many Pages to Print" & _
vbCr & vbCr & " Print Was Canceled!" & vbCr
End If
End Sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox vbCr & "There is no data for this report." & vbCr & vbCr & "
Canceling report..." & vbCr & vbCr
Cancel = True
End Sub
Private Sub Report_Open(Cancel As Integer)
If IsNull(Me.OpenArgs) Then
Cancel = True
End If
FrmtCnt = 0
End Sub
Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
FrmtCnt = FrmtCnt + 1
End Sub
Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As Integer)
If FrmtCnt > 2 Then
Cancel = True
Reports(Me.Name).Printer.Copies = 0
End If
End Sub
The only way to get the report to open in preview is to issue the following
from a module other than the reports own.
DoCmd.OpenReport "PreviewOnlyFrm", acViewPreview, , , acWindowNormal,
"PrViewOnly"
The OpenArgs does not need to be “PrViewOnly “. It can be anything but NULL.
Have Fun,
Garry