Class: PrintDialog in Category Windows : Common Dialogs from Total Visual SourceBook

Displaying the Print Common Dialog without using the Microsoft Windows Common Dialog Control in VB6 and VBA with 32 and 64-bit Windows API calls.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the CPrintDialog class.
Collate Property Determine if Collate option is selected.
All Property Determine if All option is selected.
Copies Property Get the number specified in the Copies text box of the printer dialog box.
Note: Printers with built-in support for printing multiple copies, this property always returns 1, but the correct number is printed.
Flags Property Get the bitwise flags used when displaying the Printer dialog. Multiple flags are specified by combining them in OR clauses (e.g. PrintDialog.Flags = priPageNum Or priCollate).
FromPage Property Get the value in the From text box on the printer dialog.
Max Property Get the maximum printer page number that FromPage and ToPage can return.
Min Property Get the minimum printer page number that FromPage and ToPage can return.
ToPage Property Get the value in the From text box on the printer dialog.
Class_Initialize Initialize Set initial values to defaults which may be overridden with property settings.
SetPrintRange Method Set the print range of pages numbers.
Show Method Displays the Print common dialog.
' Example of CPrintDialog
'
' To use this example, create a new module and paste this code into it.
' Then run the procedure by putting the cursor in the procedure and pressing:
'    F5 to run it, or
'    F8 to step through it line-by-line (see the Debug menu for more options)

Private Sub Example_CPrintDialog()
  ' Comments: Examples of using the CPrintDialog class to control the Windows Print Dialog from VB6 and VBA with 32 and 64 bit Windows API calls.
  '           The Printer dialog is displayed twice. The first with the default settings and the second with customized values.
  '           The dialog doesn't print anything, so feel free to press the OK button.

  Dim clsPrintDialog As CPrintDialog
  Dim intLoop As Integer

  For intLoop = 1 To 2
    Set clsPrintDialog = New CPrintDialog
    If intLoop = 1 Then
      ' Use default settings
    Else
      ' Set flags as desired
      'clsPrintDialog.Flags = priUseDevModeCopies Or priAllPages Or priNoPageNums Or priReturnDC Or priDisablePrintToFile Or priNoSelection

      ' Usually, the selection option is disabled for the print range
      clsPrintDialog.Flags = priNoSelection

      ' Rather than defaulting to All pages, set the default page range
      Call clsPrintDialog.SetPrintRange(2, 5)

      ' Set the number of copies to print if it's more than one
      clsPrintDialog.Copies = 3

      ' Turn on collation option
      clsPrintDialog.Collate = True
    End If

    ' Show dialog and test if OK was selected
    If clsPrintDialog.Show() Then
      ' Show user selections in Immediate Window
      Debug.Print "All Pages: " & clsPrintDialog.All
      If Not clsPrintDialog.All Then
        Debug.Print "From Page: " & clsPrintDialog.FromPage
        Debug.Print "To Page  : " & clsPrintDialog.ToPage
      End If

      Debug.Print "Copies   : " & clsPrintDialog.Copies
      Debug.Print "Collate  : " & clsPrintDialog.Collate
      Debug.Print
    Else
      Debug.Print "Cancel selected"
    End If

    ' Clean up
    Set clsPrintDialog = Nothing
  Next intLoop

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS