Applies to: IPrinterEx object
  Return Type:   |   None.   | |||
  | ||||
  Parameter(s):   | ||||
   In   |   Required   |   Object   |   As   |   Object   |
   In   |   Required   |   ProcedureName   |   As   |   String   |
   In   |   Optional   |   ParametersArray   |   As   |   Variant   |
Using the IPrinterEx object instead of a PrintPreview control is possible to have print preview capabilities from a Class module where no controls can be placed, or even from forms if you prefer.
Alternatively you can have the PrepareReport event by setting the PrinterExEvents object returned by the Events property.
The IPrinterEx is the interface of a global object that can be obtained with the PrintPreview global property.
Using this object, there are two ways to call the printing procedure, one is using events, for that see Events property. The other is to set the printing procedure with this method.
Parameters explained:
Object: this must be a reference to the class module, form or object where the printing procedure is.
ProcedureName: the name of the printing procedure. This procedure must be Public.
ParametersArray: if the printing procedure has parameters, they can come in an array here.
Example without parameters:
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 Sub PrintPreviewMyReport1() PrintPreview.SetPrintingProcedure Me, "MyPrintingProcedure", Array(1, 14) ' ReportNumber = 1, TitleFontSize = 14 PrintPreview.ShowPreview End Sub Public Sub PrintPreviewMyReport2() PrintPreview.SetPrintingProcedure Me, "MyPrintingProcedure", Array(2, 18) ' ReportNumber = 1, TitleFontSize = 14 PrintPreview.ShowPreview End Sub Public Sub MyPrintingProcedure(ReportNumber As Long, TitleFontSize As Long) If ReportNumber = 1 Then Printer.FontSize = TitleFontSize Printer.Print "Report 1" Printer.FontSize = 12 Printer.Print "Hello Word" ' continue with the printing code Else Printer.FontSize = TitleFontSize Printer.Print "Report 2" Printer.FontSize = 12 Printer.Print "Hello Word" ' continue with the printing code End If End Sub