Solved

Changing the default printer

Posted on 1998-08-26
7
159 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ return type for nested group query 6 74
DO Loop not working 4 72
Help with retrieving partial value from a column using VB.NET 4 44
Excel Automation VBA 19 38
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now