[AccessD] Report printed or previewed

A.D.Tejpal adtp at airtelmail.in
Fri Jul 18 11:24:17 CDT 2008


Steve,

    One way for programmatic detection of report's open status (Print or Preview) could be by checking whether the print event of page header on page 2 has fired closely after Page event on page 1. Of course this presumes a report sized more than one page.

    Sample code in report's module, as given below, should be able to do the needful.

    Detecting print preview status could be somewhat trickier, as the report can sit on page 1 itself for a prolonged period. Thus we can not keep waiting for the print event on page 2 to fire. For tackling this situation, we can use form's Timer event. Sample code in form's module, as given below, in conjunction with the global variable in general module as shown, should be able to detect print preview status of the report.

Best wishes,
A.D.Tejpal
------------

' Code in report's module
'=================================
' Declarations section
Private Tm As Long
'--------------------------------------------------

Private Sub PageHeaderSection_Print(Cancel As Integer, PrintCount As Integer)
    If Me.Page = 2 Then
        ' Confirm firing of page feader print event
        ' on page 2
        PgHdrPg2 = True
        
        ' If this event follows closely after Page
        ' event on page 1, it is Print Mode
        If Timer - Tm < 2 Then
            MsgBox "Report In Print Mode"
        End If
    End If
End Sub
'--------------------------------------------------

Private Sub Report_Page()
    If Me.Page = 1 Then
        ' Get the time when Page event on
        ' page 1 fires
        Tm = Timer
        
        ' Set default value for global variable.
        ' (signifies firing of page feader print
        ' event on page 2)
        PgHdrPg2 = False
        
        ' Set form level counter to 0
        ' Start form's Timer
        Forms("F_Report").Ctr = 0
        Forms("F_Report").TimerInterval = 500
    End If
End Sub
'=================================

' Code in general module
'=================================
' Declarations section
' Global variable confirming firing of page
' header print event on page 2
Public PgHdrPg2 As Boolean
'=================================

' Code in form's module (Form F_Report)
'=================================
' Declarations section
' Form Timer counter
Public Ctr As Long
'--------------------------------------------------

Private Sub Form_Timer()
    Ctr = Ctr + 1
    If Ctr > 2 Then
        If PgHdrPg2 = False Then
            ' Page header print event of page 2
            ' has failed to fire shortly after Page
            ' event of page 1.
            MsgBox "Report In Preview Mode"
        End If
        
        ' Reset the counter and close the Timer
        Ctr = 0
        Me.TimerInterval = 0
    End If
End Sub
'=================================

  ----- Original Message ----- 
  From: Steve Schapel 
  To: Access Developers discussion and problem solving 
  Sent: Thursday, July 17, 2008 14:30
  Subject: [AccessD] Report printed or previewed


  Does anyone know of a way to programmatically determine whether a report 
  is being previewed or printed?  Preferably for the report itself to be 
  "serlf-aware" :-) i.e. on the report's Open or Load event some code to 
  run conditional on whether it is being printed or opened in print preview?

  Regards
  Steve


More information about the AccessD mailing list