Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Using PDF reDirect
 EXP Systems Forum : PDF reDirect : Using PDF reDirect
Topic: Change Default Printer Post Reply Post New Topic
Author Message

Joined: 06 Jan 08
Posts: 13
Quote JackR Replybullet Topic: Change Default Printer
    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.

IP IP Logged
Moderator Group
Moderator Group
Forum Administrator

Joined: 25 Jan 03
Posts: 1641
Quote Michel_K17 Replybullet 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 Korwin-Szymanowski
EXP Systems LLC
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum