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
Printable View
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
Sure thing!
Then you can call this function like this: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
Note: if you have network printers installed andCode:Private Sub Command1_Click()
Call ChangeDefaultPrinter("HP 2000C")
End Sub
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,