sashi 1,754
Recognized Expert Top Contributor Set default printer
You will often find yourself in a position where you have designed a report format for one printer and when that report is sent to another printer the layout is messed up.
The following code will allow you to specify the printer that reports are sent to by reseting the systems default printer.
Windows API/Global Declarations -
Public Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
-
-
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
-
Public Const HWND_BROADCAST = &HFFFF&
-
Public Const WM_WININICHANGE = &H1A
-
Code -
Public Function SetDefaultPrinter(objPrn As Printer) As Boolean
-
Dim x As Long, sztemp As String
-
sztemp = objPrn.DeviceName & "," & objPrn.DriverName & "," & objPrn.Port
-
x = WriteProfileString("windows", "device", sztemp)
-
x = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0&, "windows")
-
End Function
-
-
Private Sub Command1_Click()
-
Dim x As Printer
-
If MsgBox("Are You Sure Want To Set " & Combo1.Text & " as Default printer ? ", vbYesNo, "Attention") = vbYes Then
-
-
For Each x In Printers
-
If x.DeviceName = Combo1.Text Then
-
SetDefaultPrinter x
-
Exit Sub
-
End If
-
Next
-
-
End If
-
End Sub
-
-
Private Sub Form_Load()
-
Dim x As Printer
-
Dim y As Integer
-
y = 0
-
-
With Combo1 'Scan all available printer and put them
-
For Each x In Printers 'in To combo box.
-
.AddItem x.DeviceName, y
-
y = y + 1
-
Next
-
.ListIndex = 0
-
End With
-
-
End Sub
-
2 17359
Absolute amazin. But there a problem, SendMessage(HWN D_BROADCAST, WM_WININICHANGE , 0&, "windows") in sometimes, crash my aplication. Any tip to resolve this problem?!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Pablo |
last post by:
Friends,
how can i get the name of the default printer??. I'm
working with winforms. VB,C#, nevermind.
Thanks a lot
Pablo
|
by: Esmee |
last post by:
Hi there,
I have created an Access 2002 db which contains several reports. Some
reports need to be printed on a Laserjet and others on a Labelprinter.
One of my clients wants to be able to print the same reports to 3
different laserjets and to 3 different labelprinters. (They work with
the db on 3 different units each with their own Laserjet and
Labelprinter)
For each unit there is a copy of all the reports.
The client can make a unit...
|
by: MLH |
last post by:
I would like to allow users to set, as an application default, a
specific printer to send reports to. I don't know how to bring up
a list of valid print devices in A97, nor do I know how to reference
any one of them that might be selected.
For instance, if I click Start, Control Panel, Printers and Faxes on
a PC running XP and I see the following:
HP Laser Jet 4200 PCL 6
HP Laser Jet 4200 PCL 5e
HP Laser Jet III
|
by: Willem |
last post by:
Hi,
I'm trying to get the default printer using WMI.
I use the following code:
Private Function GetDefaultPrinter() As String
Dim objWMIService As Object
Dim colInstalledPrinters As Object
Dim objPrinter As Object
|
by: Raymond Martin |
last post by:
How do I find out if the default printer is offline or online (or has a
paper jam)?
| |
by: Karthick_Microsoft |
last post by:
Actually, in my ASP.Net application, i have a requirement of
automatically changing the default printer. I did a OCX using VB and
put it on the web page. The client machines do not have local printers
but network printers (they have been mapped using Local Port pointing
to \\machine\printer - this was suggested in a topic - for a reason
that a network printer can be given a friendly name) - But when I click
on Print from the browser...
|
by: i8mypnuts |
last post by:
Could someone please help? I am using the 'defaultprt.zip' tool
provided by Ken Getz to change the default printer via VBA code (code
below). My problem is that once the default printer has been changed,
Access 2003 still directs the report to the former default printer.
Access 2003 picks up the new default printer setting only after I have
reopened the application. I have checked the default printer setting in
the OS control panel and the...
|
by: groulder |
last post by:
hi all,
i have a problem with a network database that's used by a lot of
people.
people are finding, they will start the database, and if the mouse is
moved over the print icon, the tooltip appears to show which printer it
will print to as normal. this printer however is a printer that the
user doesn't even have installed.
|
by: brianflannery |
last post by:
Greetings all!
My problem is this. I've installed a new printer on my computer.
This is the "default printer" for access. Now, some of my reports,
which were working fine with the old printer, are now showing up with
an odd view (very enlarged) in preview. If I go to page setup, and
choose specific printer to then look at the paper size listed in my
default printer, it shows Hegaki Card 100mmX148mm instead of letter.
It seems as...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |