Solved

Changing the default printer

Posted on 1998-08-26
7
163 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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