Link to home
Start Free TrialLog in
Avatar of dgwest
dgwest

asked on

Changing the default printer

In an Access database, I would like to change the 'On Click' property in the print button I have set up, to print to a specific printer.  I would like to set up three print buttons that lead to three different printers. How do I change which printer I print to?
Avatar of mcix
mcix

Are we working in Access or Visual Basic?
dgwest,
Try this code:

' 1. API declaration

          Const HWND_BROADCAST = &HFFFF&
          Const WM_WININICHANGE = &H1A

          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 WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As
          String, ByVal lpszString As String) As Long

          Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As
          Long, lParam As Any) As Long



'     2. in the click event add

         
          Dim S As String, length As Long, hKey As Long

          PrinterName = "HP LaserJet 4L"
          S = String(80, Chr(0))
          length = GetProfileString("devices", PrinterName, "", S, Len(S))
          S = Left(S, length)
          Call WriteProfileString("windows", "device", PrinterName & "," & S)
          Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, &H7FFF&, ByVal "windows")

Regards
Dalin
Avatar of dgwest

ASKER

Access.
Avatar of dgwest

ASKER

What is does API stand for? I understand the code for the on click event, but where does the API declaration go?  I am working in Access.
Avatar of dgwest

ASKER

What does the API stand for?
Avatar of dgwest

ASKER

I'm sorry that I rejected your answer, Dalin, it may be just what I am looking for.  This is my first question and I didn't know if I could recieve comments on this page or not if the proposed question was there.  If your proposed answer is correct, I will give you the points.  

Sorry again,
Derek
ASKER CERTIFIED SOLUTION
Avatar of Dalin
Dalin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial