Solved

Changing the default printer

Posted on 1998-08-26
7
158 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

22 Experts available now in Live!

Get 1:1 Help Now