Results 1 to 2 of 2

Thread: Change default printer ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    16

    Post

    Hello

    I need to change the default printer
    and then print something from a report.

    but it keeps on ending up on the wrong printer.

    I think i need to use API bud dont know how.

    anybody ?

    Thanks in advance
    Micke

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Sure thing!
    Code:
    Option Explicit
    Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
    
    Private Function ChangeDefaultPrinter(p_strPrinterName As String) As Boolean
        Dim prn As Printer
        Dim blnIsFound As Boolean
        Dim strBuffer As String
        
        For Each prn In Printers
            If UCase(p_strPrinterName) = UCase(prn.DeviceName) Then
                strBuffer = prn.DeviceName & "," & prn.DriverName & "," & prn.Port
                blnIsFound = True
                Exit For
            End If
        Next
        
        If blnIsFound Then
            Call WriteProfileString("windows", "device", strBuffer)
            ChangeDefaultPrinter = True
        End If
    End Function
    Then you can call this function like this:
    Code:
    Private Sub Command1_Click()
        Call ChangeDefaultPrinter("HP 2000C")
    End Sub
    Note: if you have network printers installed and
    you want to change one of them to be your default printer, then you would have to pass full network path as a printer
    name, i.e Call ChangeDefaultPrinter("\\ComputerName\HP 2000C")

    Regards,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width