Global object that can be used instead of a PrintPreview control, for example in class modules.
This object uses this interface, which is returned by the class Global from its property PrintPreview.
It has the same properties and methods of the PrintPreview control, but it is a global object and it doesn't require a form to stay on, thus allowing to print from class modules.
Being a global object it does not require to be instantiated.
The usage for most of the properties and actions is the same as for a PrintPreview control.
But it has another way to handle events and to call the printing routine.
To handle, events see the property Events which returns an PrinterExEvents object.
There are two ways of calling the printing routine:
First option: To use the PrepareReport event of the PrinterExEvents object returned by the Events property.
Sample usage in a class module:
Private WithEvents mPrinterExEvents As PrinterExEvents
Private Sub Class_Initialize()
Set mPrinterExEvents = PrintPreview.Events
End Sub
Public Sub PrintPreviewMyReport() ' This is the method that will be called to show the print preview dialog with the report
PrintPreview.ShowPreview
End Sub
Private Sub mPrinterExEvents_PrepareReport(Cancel As Boolean)
MyPrintingProcedure
End Sub
Private Sub MyPrintingProcedure()
Printer.Print "Hello Word"
' continue with the printing code
End Sub
Private Sub Class_Initialize()
PrintPreview.SetPrintingProcedure Me, "MyPrintingProcedure"
End Sub
Public Sub PrintPreviewMyReport() ' This is the method that will be called to show the print preview dialog with the report
PrintPreview.ShowPreview
End Sub
Public Sub MyPrintingProcedure()
Printer.Print "Hello Word"
' continue with the printing code
End Sub
Public Property Get Printer() As Printer
Set Printer = BSPrinter.PrinterReplacement
End Property
Public Property Set Printer(nPrinter As Printer)
Set BSPrinter.PrinterReplacement = nPrinter
End Property
Properties
AllowUserChangeMarginsMethods
AddWatermark