Solved

Changing the default printer

Posted on 1998-08-26
7
161 Views
Last Modified: 2010-04-30
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?
0
Comment
Question by:dgwest
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1431101
Are we working in Access or Visual Basic?
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1431102
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
0
 

Author Comment

by:dgwest
ID: 1431103
Access.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:dgwest
ID: 1431104
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.
0
 

Author Comment

by:dgwest
ID: 1431105
What does the API stand for?
0
 

Author Comment

by:dgwest
ID: 1431106
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
0
 
LVL 9

Accepted Solution

by:
Dalin earned 100 total points
ID: 1431107
Derek,

API stands for Application Programmer's Interface (don't ask me why such a name because it puzzles me too). They are just a bouch of window functions you can use for most microsoft stuff(VB, Access, Excel.. )

The declaration part should go ofter the line of "option explicit" in your form. (you should see it from the code builder.

Regards
Dalin


0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question