Detecting report view mode (Print Preview vs Printing)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way within VBA to tell whether the onPrint event of a section is
being called in print preview mode or in print mode?

I am trying to increment a counter when a page is actually printed but not
when the report is viewed in print preview mode. The onPrint event appears
to be being called in print preview mode AND when the page is actually
printed.
 
Is there a way within VBA to tell whether the onPrint event of a section is
being called in print preview mode or in print mode?

I am trying to increment a counter when a page is actually printed but not
when the report is viewed in print preview mode. The onPrint event appears
to be being called in print preview mode AND when the page is actually
printed.

The actual starting value of intPreview depends upon if you have a
control in the report to compute [pages]. Use the correct line for
your report.

Note that intPreview is Dimmed up in the Declarations section.

Option Compare Database
Option Explicit
Dim intPreview As Integer

Private Sub Report_Activate()
intPreview = -1 ' If [Pages] is not used
' intPreview = -2 ' If [Pages] used
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As
Integer)
If intPreview >= 0 Then ' If [Pages] not used
' If intPreview >= 1 Then ' If [Pages] used
MsgBox "Sent to print out"
' You can place whatever additional stuff you wish done here
End If
intPreview = intPreview + 1
End Sub

A note of caution. Just because you send the report to be printed
doesn't mean it was successfully printed. Printers do run out of paper
or ink, as well as pass away quietly in the night.
 
Thanks for the input. I will try this.

fredg said:
Is there a way within VBA to tell whether the onPrint event of a section is
being called in print preview mode or in print mode?

I am trying to increment a counter when a page is actually printed but not
when the report is viewed in print preview mode. The onPrint event appears
to be being called in print preview mode AND when the page is actually
printed.

The actual starting value of intPreview depends upon if you have a
control in the report to compute [pages]. Use the correct line for
your report.

Note that intPreview is Dimmed up in the Declarations section.

Option Compare Database
Option Explicit
Dim intPreview As Integer

Private Sub Report_Activate()
intPreview = -1 ' If [Pages] is not used
' intPreview = -2 ' If [Pages] used
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As
Integer)
If intPreview >= 0 Then ' If [Pages] not used
' If intPreview >= 1 Then ' If [Pages] used
MsgBox "Sent to print out"
' You can place whatever additional stuff you wish done here
End If
intPreview = intPreview + 1
End Sub

A note of caution. Just because you send the report to be printed
doesn't mean it was successfully printed. Printers do run out of paper
or ink, as well as pass away quietly in the night.
 
Back
Top