473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Print to Specific Printer

I have a button that prints a report and runs a query to update the records whose invoice was printer.

I have the report setup to print on a specific printer.

It's been working fine for months, then all of a sudden yesterday it printed on our mono machine instead of our colour one. Which meant I had to go into the queries and reset the ones that had been updated.
When I opened the report in design view and it said the specific printer was unavailable, so I reselected it (exactly the same IP, name, everything), saved and it ran fine.

This morning, same thing happened again!

I can't have this happening every day so I'm wondering if there's any VBA I can add to the onPage event to make sure it selects the right printer?


Thanks
Mandi

Edit:
I just found this code:
Expand|Select|Wrap|Line Numbers
  1. reports(0).Printer.devicename = "My Printer" 
But it would be easier if I could specify it using the IP address instead of the name, as there's 20+ computers and I can't be sure that everyone has the same printer name setup, but obviously the IP doesn't change.
Mar 26 '09 #1
10 11281
NeoPa
32,556 Expert Mod 16PB
Printer objects have a Port property where an IP address, if used specifically, should appear. Not all printers use IP addressing ports, and not all that do use the IP address in its native form (mine for instance always refer to the name of the device although they are ports that address it via IP).

Assuming for now though, that your ports indicate the IP address somehow though, there is also a collection of Printers available. If you were to cycle through this collection looking for a printer whose port matched what you were after, then assign this printer to your report, then that should work for you.
Expand|Select|Wrap|Line Numbers
  1. Set Reports("Your report name").Printer = _
  2.         Printers("Found Printer Name")
Mar 26 '09 #2
Ah.
Each computer in the company has a random number of installed printers all attached via IP, mine for instance currently has 21. Most of the other computers were set up before I got here (which is why I don't know who has which, what each one is called etc.)

In the Printer properties, the Port Name is IP_xx.xx.xx.xx (obviously xx is the specific IP address), I'm assuming that's the part you mean?
Mar 26 '09 #3
NeoPa
32,556 Expert Mod 16PB
@mandanarchi
It is, but what is the name of your report?
Mar 26 '09 #4
NeoPa
32,556 Expert Mod 16PB
Try working with this basic code. The name of the report and the IP address (in standard x.x.x.x format) are the two parameters required :
Expand|Select|Wrap|Line Numbers
  1. Public Sub UsePrinterIP(strReport As string, ByVal strIP As String)
  2.   Dim ptrThis As Printer
  3.  
  4.   strIP = "IP_" & strIP
  5.   For Each ptrThis In Printers
  6.     If ptrThis.Port = strIP Then Exit For
  7.   Next ptrThis
  8.   If ptrThis.Port = strIP Then
  9.     Set Reports(strReport).Printer = ptrThis
  10.   Else
  11.     Call MsgBox("...not worked...")
  12.   End If
  13. End Sub
Mar 26 '09 #5
Run-time error '91':
Object variable or With block variable not set

Error on this line
Expand|Select|Wrap|Line Numbers
  1. If ptrThis.Port = strIP Then
Mar 26 '09 #6
NeoPa
32,556 Expert Mod 16PB
That means the ptrThis object variable is unset. There was no printer found to match the criteria. This is the part that you pick up with and progress yourself if you can.

If not then I will need a reasonable explanation why before simply doing it for you. This is not intended to be supplying a ready-made solution, just to get you past the problem you started out with.
Mar 26 '09 #7
ChipR
1,287 Expert 1GB
Isn't that variable unset because it's ouside the scope of the For loop?
Mar 26 '09 #8
NeoPa
32,556 Expert Mod 16PB
No Chip. It's unset (or set to the value Nothing) because it didn't find any matching Printer object within the For loop.

For loops can often be used for finding a value and then using it (referring to it) when the loop has completed. In this case, we immediately detect a find and break out of the loop for this purpose.
Mar 26 '09 #9
I wasn't asking you to do it for me NeoPa, I was asking for help.
I didn't understand what the error message was saying so I asked, that's all.

I think I more or less understand it now, and Google is my friend, so thanks for all your help.

Mandi.
Mar 27 '09 #10
NeoPa
32,556 Expert Mod 16PB
Sorry if I sounded accusatory Mandi. That wasn't really my intention. I was simply trying to explain why I wasn't going further at this time.

Different people have different understandings and many it seems, need that explaining. I wasn't to know you understood it better and didn't need it ;)
Mar 31 '09 #11

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

Similar topics

0
by: Tessa | last post by:
Is there any security reason why you cannot print to a network printer from ASP.NET under IIS6 on Windows 2003 server? I'm using ASP.NET code to print to a server print queue using...
12
by: Peter Lin | last post by:
Hey, I am just wondering if anyone has got any idea of setting up a new class so that you could just print like the old ways with the printer class, since I am writing a program that really...
7
by: Mark | last post by:
Hi, I am creating application in VB 2005. and when I print report it adds extra 0.45 cm margin on left and top, and the reason for this is physical margins of printer. Is it possible to change...
1
by: gwong | last post by:
How can I tie window.print() to a specific printer? I've created a print button but don't want the pop up to occur that gives the printer selections. I am trying to minimize the number of clicks...
5
by: Carl Witte | last post by:
Hello. I'm stuck. I've got a form I need to print to a manual feeder on a shared laser printer. This will get me to the printer but I can't seem to figure out how to print it to a specific bin. ...
0
AllusiveKitten
by: AllusiveKitten | last post by:
Hi kind and helpful people... At work I am creating a database and reports that will be used by multiple people. What I need is for my reports to print to a specific colour printer and be manual...
6
convexcube
by: convexcube | last post by:
Hello Everyone, I have a form setup with a combo box that displays a list of the installed printers using code from this article. On a button called cmdPrint I have placed code in the OnClick...
10
by: Snoopy33 | last post by:
I have a DB that I developed on access XP (2002) and deployed over a year ago. No one has had problems printing any of the reports within the DB until we started loading 2007 on new computers. ...
3
by: jpas84 | last post by:
When using JavaScript window.print() command to print in IE, is it possible to set the selected printer in the Print window? In some cases I'd like to have the user's default printer selected, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
0
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...
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
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...

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.