Print Page | Close Window

Change Default Printer

Printed From: www.exp-systems.com
Category: PDF reDirect
Forum Name: Using PDF reDirect
Forum Discription: Questions and Comments on using PDF reDirect Freeware and Pro
URL: http://www.exp-systems.com/Forum_exp/forum_posts.asp?TID=469
Printed Date: 28 Mar 24 at 10:37AM


Topic: Change Default Printer
Posted By: JackR
Subject: Change Default Printer
Date Posted: 24 Jan 09 at 11:22AM
Hi Miohel

Is it possibe to change the default printer using the ActiveX Componenet? I have a VB8 Program the uses the BatchPDF printer. I need to change the default printer to the BatchPDF printer and then change it back when the job is done.


Jack



Replies:
Posted By: Michel_K17
Date Posted: 24 Jan 09 at 10:29PM
Hi Jack,

   No, the ActiveX component does not have this function.

   But, good news: the code given in the Sample Access VBA programs shows you how to do exactly that because older Access versions do not have a built-in VBA command for that.

   Here is a summary: simply use the following two functions that get and set the default printer:


' GetDefaultPrinter Function (Only required in Access)
Private Function GetDefaultPrinter() As String
    GetDefaultPrinter = Space$(1024)
    GetDefaultPrinter = Trim$(Left$(GetDefaultPrinter, GetProfileString("windows", "device", "", GetDefaultPrinter, 1024)))
End Function

' SetDefaultPrinter Function
Private Function SetDefaultPrinter(PrinterName_DriverName_PrinterPort As String) As Boolean
    WriteProfileString "windows", "device", PrinterName_DriverName_PrinterPort
    SetDefaultPrinter = CBool(SendMessageByString(&HFFFF&, &H1A, 0&, "windows"))
End Function

   You will need to declare the following Windows API functions:

    Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
    Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
    Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

   Again, the Access demo code will show you how to call the function to set the printer (it's one string with the three parameters separated by commas).

   I hope that helps,

Michel






-------------
Michel Korwin-Szymanowski
EXP Systems LLC



Print Page | Close Window