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: - 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.
10 11324 NeoPa 32,566
Recognized Expert Moderator MVP
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. - Set Reports("Your report name").Printer = _
-
Printers("Found Printer Name")
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?
NeoPa 32,566
Recognized Expert Moderator MVP @mandanarchi
It is, but what is the name of your report?
NeoPa 32,566
Recognized Expert Moderator MVP
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 : - Public Sub UsePrinterIP(strReport As string, ByVal strIP As String)
-
Dim ptrThis As Printer
-
-
strIP = "IP_" & strIP
-
For Each ptrThis In Printers
-
If ptrThis.Port = strIP Then Exit For
-
Next ptrThis
-
If ptrThis.Port = strIP Then
-
Set Reports(strReport).Printer = ptrThis
-
Else
-
Call MsgBox("...not worked...")
-
End If
-
End Sub
Run-time error '91':
Object variable or With block variable not set
Error on this line - If ptrThis.Port = strIP Then
NeoPa 32,566
Recognized Expert Moderator MVP
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.
ChipR 1,287
Recognized Expert Top Contributor
Isn't that variable unset because it's ouside the scope of the For loop?
NeoPa 32,566
Recognized Expert Moderator MVP
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
PrintDocument.Print()
(.NET framework v 1.1)
I can print to a local printer plugged into LPT1 on the web server, but not
to a network printer.
The same printing code to a network printer works in a .NET web app when
|
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 requires simple black and white
text printing, but there is alot to print and it's needed at various
places, which is why I find that the new printing style with the
printdocument a bit too clumsy.
Any help would be appreciated.
|
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 printer's physical margins using VB coding?
Cheers
--
Osmotion Blue
|
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 required to print. However, I want to tie my print button to a specific printer and print tray. In a config will i will read in the printer queue name for this specific printer. Thanks in advance for the help!
|
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. The .PaperBin appears to be nonfunctional (all things give me the same result). I took a look at the .prtDevMode and decided it was over my head. Platform is Access 2003 in an XP Enviorment.
'prints a hard copy to a specific printer name
'or...
| |
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 feed as the papersize is different.
The following coding does select the printer that I require on my computer, but as different people have different printers loaded to their machines the number of printers and the orders vary, so my coding falls...
|
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 event from the same article to print to a specific printer. The specific printer being the one chosen in the combo box. In the line:
Set rpt.Printer = Application.Printers("Acrobat PFDWriter")
I have replaced "Acrobat PFDWriter" with the name of my...
|
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. The access
2007 users cannot print one of the reports. This is maddening since I
cannot duplicate the issue on any computer that runs 2003 or below.
Is there something going on that I'm not seeing? Does anyone have any
suggestions at all on...
|
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 in other cases have a specific printer selected when the Print window is displayed.
The default behavior seems to be that the first time the Print window is displayed, the default printer is selected. After that, the last selected printer is the...
|
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: 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: 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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |