473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Changing the printer using VBA Code

11 New Member
I found most of the solution to my problem here:

http://bytes.com/topic/access/answer...inter-vba-code

I need to print to a printer that is not set as the default printer.

My question revolves around the coded solution. How do I determine what my printer needs to be referenced as in the following code:

Expand|Select|Wrap|Line Numbers
  1. Set Application.Printer = Application.Printers("HP LaserJet Series II")
Jul 29 '14 #1

✓ answered by zmbd

In a standarad module, insert the following and run.
Once you have the device name you can hardcode it.

Expand|Select|Wrap|Line Numbers
  1. Sub zListPrinterNames()
  2.     Dim zPrinters As Printers
  3.     Dim zprinter As Printer
  4.     '
  5.     Set zPrinters = Application.Printers
  6.     '
  7.     For Each zprinter In zPrinters
  8.         Debug.Print "Printer Name: ", zprinter.DeviceName
  9.     Next
  10.     MsgBox Prompt:="Please press <CTRL><G> to view the list of printers available to this application"
  11.     '
  12.     Set zPrinters = Nothing
  13. End Sub
Yes, you could build a listbox out of this too... just as easy to open the report in print preview and allow the user to select the printer by calling the printer dialog. You just need to remember to trap the error if the user cancels. (^_^)

2 1409
zmbd
5,501 Recognized Expert Moderator Expert
In a standarad module, insert the following and run.
Once you have the device name you can hardcode it.

Expand|Select|Wrap|Line Numbers
  1. Sub zListPrinterNames()
  2.     Dim zPrinters As Printers
  3.     Dim zprinter As Printer
  4.     '
  5.     Set zPrinters = Application.Printers
  6.     '
  7.     For Each zprinter In zPrinters
  8.         Debug.Print "Printer Name: ", zprinter.DeviceName
  9.     Next
  10.     MsgBox Prompt:="Please press <CTRL><G> to view the list of printers available to this application"
  11.     '
  12.     Set zPrinters = Nothing
  13. End Sub
Yes, you could build a listbox out of this too... just as easy to open the report in print preview and allow the user to select the printer by calling the printer dialog. You just need to remember to trap the error if the user cancels. (^_^)
Jul 29 '14 #2
Ashabel
11 New Member
Thank you very much.
Jul 30 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mathilda | last post by:
I am trying to send a report to a specific, non-default printer in code, bypassing the preview mode, but I cannot find the code to do so anywhere. Can anybody help?
2
by: Les Caudle | last post by:
When displaying a database driven product page, I cache the page using: <%@ OutputCache Duration="86400" VaryByParam="ProductID" %> which works fine UNLESS I change the pricing or description...
0
by: Anthony Nystrom | last post by:
I am having trouble with changing printer settings before I raise either the pagesetup dialog or the print preview dialog... Changing the printer name is easy, but I am also trying to change the...
2
by: ExitusLSU | last post by:
Is there a way to change the DEFAULT printer settings for an installed printer? I want it to change the printer settings for a specified printer at the whole OS/Windows level, not just for the...
2
by: Crazyhorse | last post by:
Hi, I am trying to print labels to a zebra printer using the print document object in vb.net. Printing works fine to my local printer but with the Zebra, the data light indicator just flickers a...
1
by: amcgary | last post by:
Hello, I am trying to print a System.Drawing.Printing.PrintDocument to a dot matrix printer using C# .NET. I have created an instance of the PrintDocument and create a event handler for the...
0
by: IQBAL AHMED | last post by:
Hi I have developed a Shopfloor Project which I want to print a Bill in Dot matrix printer using VB.Net 2005. I don't know how to write the coding, set and print. Will you help to write the...
8
by: ncsthbell | last post by:
Is there a way to change my default printer using vb? I have some reports I want to print to a certain printer and some to a different one. I have a routine that loops through all of the reports to...
8
by: Greg (codepug | last post by:
For lack of the proper expression, how do I excite a control to cause events to trigger. I have a date control and am using a calender form button to fill the text box with the date. The text box...
3
by: harini19 | last post by:
I have implemented the code to send raw data to printer using the below KB article. http://support.microsoft.com/?kbid=322091 The receipt printer works for small strings but when I send large...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.