Total Visual SourceBook

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 2007 and VB6

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

Separate version for Access/Office 2003, 2002, and 2000.

Separate version for:
Access 97/95


View all FMS products for Microsoft AccessAll Our Microsoft Access Products

SourceBook Info:

Why SourceBook?

 

"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

 

 

 

Microsoft Access, Office/VBA, VB6 Modules royalty-free source code libraryMicrosoft Access Modules royalty-free source code libraryMicrosoft Access VBA and VB6 Module Library Free trial of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA

Module: PrinterWindows in Category Windows : System Information from Total Visual SourceBook

Manage the Windows printer settings using the Printer object in VB6 and Microsoft Access (with support for 32 and 64 bit API calls).

Note that a printer object does not currently exist in VBA for Microsoft Excel.

Procedure List

Procedure Name

Type

Description

(Declarations) Declarations Declarations and private variables for the modPrinterWindows module
ChangeDefaultPrinter Procedure Change the Windows default printer to the specified printer.
DefaultPrinterName Procedure Get the name of the current Windows default printer.
PrinterInfoCommon Procedure Get the shared printer properties from the printer object from Microsoft Access and VB6. While Microsoft Access and VB6 have printer objects, their properties are not the same.
PrinterInfoAccess Procedure Get a string of information regarding the specified printer within Microsoft Access. The printer object's properties in MS Access are different from the printer object in VB6.
PrinterInfoVB6 Procedure Get a string of information regarding the specified printer within Visual Basic 6. The printer object's properties in MS Access are different from the printer object in VB6.
PrintersToArray Procedure Show all printers connected to the system
ShowPrinters Procedure Show all printers available for the current machine.

Example Code for Using Module: PrinterWindows

' Example of modPrinterWindows
'
' 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_modPrinterWindows()
  ' Comments: Example of using the modPrinterWindows module to get mouse information, with support for 32 and 64 bit API calls using VBA and VB6.
  '           Run this procedure and see the information of each printer in the Immediate Window.

  Dim strDefaultPrinter As String
  Dim astrPrinters() As String
  Dim intPrinterCount As Integer
  Dim intPrinter As Integer
  Dim strNewPrinter As String

  ' Show the list of printers in a message box
  ShowPrinters

  ' Get the current default printer name
  strDefaultPrinter = DefaultPrinterName
  Debug.Print "Default printer: " & strDefaultPrinter

  ' Get the list of printers
  intPrinterCount = PrintersToArray(astrPrinters)
  Debug.Print "Available printers: " & intPrinterCount

  ' For each printer, show its details
  For intPrinter = 0 To intPrinterCount - 1
    Debug.Print astrPrinters(intPrinter)

    ' This retrieves the common properties from the Printer object in Microsoft Access and VB6
    Debug.Print PrinterInfoCommon(intPrinter)

    ' Use this for the complete list of porperties available for Microsoft Access
    'Debug.Print PrinterInfoAccess(intPrinter)

    ' Use this for the complete list of porperties available for VB6
    'Debug.Print PrinterInfoVB6(intPrinter)

    Debug.Print "-----------------------------"
  Next intPrinter

  ' Show how to change the default printer (assuming one already exists)
  If strDefaultPrinter <> "" Then
    ' Find the first printer that's not the current default printer
    strNewPrinter = ""
    For intPrinter = 0 To intPrinterCount - 1
      If astrPrinters(intPrinter) <> strDefaultPrinter Then
        strNewPrinter = astrPrinters(intPrinter)
        Exit For
      End If
    Next intPrinter

    ' If there's another printer to switch to, show how it's done
    If strNewPrinter <> "" Then
      If MsgBox("This example will change your default printer from " & strDefaultPrinter & " to " & strNewPrinter & " then reset it to the original printer." & vbCrLf & _
                "If the code is interrupted or fails, your default printer may be changed incorrectly. " & vbCrLf & _
                "Would you like to continue?", vbQuestion + vbYesNo) = vbYes Then
        ' Change the Default Printer
        Debug.Print "Changing the default printer."

        If ChangeDefaultPrinter(astrPrinters(0)) Then
          ' Confirm the default printer is changed by retrieving the value again
          Debug.Print "Default printer changed to: " & DefaultPrinterName

          Debug.Print "Changing the default printer back to the original value."
          If ChangeDefaultPrinter(strDefaultPrinter) Then
            ' Confirm the default printer is reset by retrieving the value again
            Debug.Print "Default printer changed to: " & DefaultPrinterName
          Else
            Debug.Print "Default printer could not be changed."
          End If
        Else
          Debug.Print "Default printer could not be changed."
        End If
      End If
    End If
  End If

End Sub

Microsoft Access Module LibraryOverview of 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.

Additional Resources