VBA and API

D

DS

Hi,
Not sure if this is the right place, let me know if its not. I recently
downloaded code from Jonathan West that kicks back the staus of your
printer before you print. The problem is it returns the status of whats
in the Print Que, "this works fine", not whats connected to the
computer either locally or accross the network. I need to find if the
printer is able to print a report and if it's not, because it lacks
paper or is offline, then send it to another printer. Is there a way to
do this? I'm using Access 2002.
Thanks
DS
 
K

Karl E. Peterson

DS said:
Not sure if this is the right place, let me know if its not. I
recently downloaded code from Jonathan West that kicks back the staus
of your printer before you print. The problem is it returns the
status of whats in the Print Que, "this works fine", not whats
connected to the computer either locally or accross the network. I
need to find if the printer is able to print a report and if it's
not, because it lacks paper or is offline, then send it to another
printer. Is there a way to do this? I'm using Access 2002.

I believe the only place Windows exposes this information is through the print queue.
 
D

DS

Karl said:
I believe the only place Windows exposes this information is through the print queue.
OH Boy, how can I do this? I've seen other applications send up an
Error Box whenver a printer is offline, how is this done? Without even
sending a print job. Also is there a way to monitor the print spooler,
and send a message from there?
Thanks
DS
 
K

Karl E. Peterson

DS said:
OH Boy, how can I do this? I've seen other applications send up an
Error Box whenver a printer is offline, how is this done? Without
even sending a print job. Also is there a way to monitor the print
spooler, and send a message from there?

You can get the status of any given printer pretty easily. Didn't mean to confuse
things by using the term "pring queue." All the same group of stuff. IOW, what you
see in the queue is the same info that's available to you.

What you'll need to do is call GetPrinter, and check the Status member (of the
PRINTER_INFORMATION_2 structure that's returned) for the PRINTER_STATUS_OFFLINE flag.
It's not a pretty API to call, but that's what Windows (NT) offers. There's a
functional example that shows this (in CPrinterInfo.cls), and a *lot* more, at
http://vb.mvps.org/samples/PrnInfo. I've never used that class in VBA, but I'm told
it drops right in.

Earlier versions of Windows, 9x and 3.x, allowed direct port I/O. I wonder if that's
what you're remembering? Directly probing a printer port, you could tell whether an
attached printer was on or offline. Those are days gone by, however.
 
D

DS

Karl said:
You can get the status of any given printer pretty easily. Didn't mean to confuse
things by using the term "pring queue." All the same group of stuff. IOW, what you
see in the queue is the same info that's available to you.

What you'll need to do is call GetPrinter, and check the Status member (of the
PRINTER_INFORMATION_2 structure that's returned) for the PRINTER_STATUS_OFFLINE flag.
It's not a pretty API to call, but that's what Windows (NT) offers. There's a
functional example that shows this (in CPrinterInfo.cls), and a *lot* more, at
http://vb.mvps.org/samples/PrnInfo. I've never used that class in VBA, but I'm told
it drops right in.

Earlier versions of Windows, 9x and 3.x, allowed direct port I/O. I wonder if that's
what you're remembering? Directly probing a printer port, you could tell whether an
attached printer was on or offline. Those are days gone by, however.
Thanks Karl, I downloaded the example started it up, I saw my printers.
So I popped the lid on one of them and tried to print to it, it said
ready, so I went to the Que and that said printing....I waited nothing
happened. So where is this functional example of CPrinterInfo.cls ?
Thank you for your help.
DS
 
K

Karl E. Peterson

DS said:
Thanks Karl, I downloaded the example started it up, I saw my
printers. So I popped the lid on one of them and tried to print to
it, it said ready, so I went to the Que and that said printing....I
waited nothing happened. So where is this functional example of
CPrinterInfo.cls ? Thank you for your help.

That sample fairly well (in my experience) replicates what Windows shows. Are you
seeing the same thing as you do if you Open Printers? In general, I find the status
info to be woefully lacking, and often not updated until you actually try to print.
 
D

DS

Karl said:
You can get the status of any given printer pretty easily. Didn't mean to confuse
things by using the term "pring queue." All the same group of stuff. IOW, what you
see in the queue is the same info that's available to you.

What you'll need to do is call GetPrinter, and check the Status member (of the
PRINTER_INFORMATION_2 structure that's returned) for the PRINTER_STATUS_OFFLINE flag.
It's not a pretty API to call, but that's what Windows (NT) offers. There's a
functional example that shows this (in CPrinterInfo.cls), and a *lot* more, at
http://vb.mvps.org/samples/PrnInfo. I've never used that class in VBA, but I'm told
it drops right in.

Earlier versions of Windows, 9x and 3.x, allowed direct port I/O. I wonder if that's
what you're remembering? Directly probing a printer port, you could tell whether an
attached printer was on or offline. Those are days gone by, however.
Say your article in Visual Studio Magazine,,,it shows paused
unavailable, all kinds of different status, but when I run your example
I only get ready?
Thanks
DS
 
D

DS

Karl said:
That sample fairly well (in my experience) replicates what Windows shows. Are you
seeing the same thing as you do if you Open Printers? In general, I find the status
info to be woefully lacking, and often not updated until you actually try to print.
No I see Printing from the windows Que and Ready from your Que
Thanks
DS
 
D

DS

Karl said:
That sample fairly well (in my experience) replicates what Windows shows. Are you
seeing the same thing as you do if you Open Printers? In general, I find the status
info to be woefully lacking, and often not updated until you actually try to print.
Ok I see what you mean, it says printing, just like in windows. But
status is ready when I take it offline.
DS
 
K

Karl E. Peterson

DS said:
Ok I see what you mean, it says printing, just like in windows. But
status is ready when I take it offline.

In both the print queue and my sample? (Repeat experience that status updates suck
bigtime.)
 
K

Karl E. Peterson

DS said:
Say your article in Visual Studio Magazine,,,it shows paused
unavailable, all kinds of different status, but when I run your
example I only get ready?

"Ready" is pretty much the absence of any noted status. Windows (is there an echo in
here? <g>) isn't very good at reporting actual status, and then it too is reliant on
the drivers supplied by manufacturers, and so on.

I hear you. I'm not brushing you off. But I have a laserjet here, hooked directly
to my machine, and if I set it Offline, Windows doesn't seem to recognize that at
all. Even if I print to it, it just shows "Printing" -- Windows, not my sample.

Ah, maybe this will clarify?

"The status of printers and print jobs are updated by the Win32 Spooler during the
despool of a print job. At all other times, when that printer is not despooling and
reports no state information, the printer is considered to be ready and idle."
- http://support.microsoft.com/default.aspx?scid=kb;en-us;160129

In fact, this is exactly the article you need to read. It goes on to say:

"Consequently, a system Printer reports no status when the Printer queue is empty.
In this state, the Printer is assumed ready to accept print jobs. This is a valid
assumption even if the physical printer is in an error state such as off-line. The
operating system considers the Printer ready to accept print jobs even if, for some
reason, it cannot complete delivery to the physical printer. Such a circumstance is
considered an error state in the operating system that must be addressed by the user.
It is not considered an error reportable to the application that is allowed to
complete the spooling of the print job successfully."

So, well, there you have it, eh?

Sorry... Karl
 
D

DS

Karl said:
"Ready" is pretty much the absence of any noted status. Windows (is there an echo in
here? <g>) isn't very good at reporting actual status, and then it too is reliant on
the drivers supplied by manufacturers, and so on.

I hear you. I'm not brushing you off. But I have a laserjet here, hooked directly
to my machine, and if I set it Offline, Windows doesn't seem to recognize that at
all. Even if I print to it, it just shows "Printing" -- Windows, not my sample.

Ah, maybe this will clarify?

"The status of printers and print jobs are updated by the Win32 Spooler during the
despool of a print job. At all other times, when that printer is not despooling and
reports no state information, the printer is considered to be ready and idle."
- http://support.microsoft.com/default.aspx?scid=kb;en-us;160129

In fact, this is exactly the article you need to read. It goes on to say:

"Consequently, a system Printer reports no status when the Printer queue is empty.
In this state, the Printer is assumed ready to accept print jobs. This is a valid
assumption even if the physical printer is in an error state such as off-line. The
operating system considers the Printer ready to accept print jobs even if, for some
reason, it cannot complete delivery to the physical printer. Such a circumstance is
considered an error state in the operating system that must be addressed by the user.
It is not considered an error reportable to the application that is allowed to
complete the spooling of the print job successfully."

So, well, there you have it, eh?

Sorry... Karl
Thanks Karl....

Such a circumstance is considered an error state in the operating system
that must be addressed by the user.

Does this mean that I have to figure out to fix it? Or does this mean
that this is just the way it is?

Karl,
I've seen POS systems with VB front and Access Back where they are
constanly searching the system and when a printer goes offline an error
message is flashed. How is this done?
Thanks
DS
 
K

Karl E. Peterson

DS said:
Such a circumstance is considered an error state in the operating
system that must be addressed by the user.

Does this mean that I have to figure out to fix it? Or does this mean
that this is just the way it is?

You, as user, would need to fix it, yeah. No way for Windows to reach out, and press
the Offline button on your printer, or fill up the paper tray. You, as developer,
don't care. said:
I've seen POS systems with VB front and Access Back where they are
constanly searching the system and when a printer goes offline an
error message is flashed. How is this done?

My gut says those were bypassing, or using older versions of, Windows. Here's a few
hints:

http://www.google.com/search?q=nt+"port+i/o"+vb

You might find these useful:

http://www.logix4u.net/inpout32.htm
http://www.lvr.com/files/test_inpout32_vb6.zip

In short, you're looking at rolling up your sleeves, and getting a bit dirty.
Unfortunately, it isn't an area I've ever done more than think/read about
occassionally.
 
D

DS

Karl said:
You, as user, would need to fix it, yeah. No way for Windows to reach out, and press
the Offline button on your printer, or fill up the paper tray. You, as developer,



My gut says those were bypassing, or using older versions of, Windows. Here's a few
hints:

http://www.google.com/search?q=nt+"port+i/o"+vb

You might find these useful:

http://www.logix4u.net/inpout32.htm
http://www.lvr.com/files/test_inpout32_vb6.zip

In short, you're looking at rolling up your sleeves, and getting a bit dirty.
Unfortunately, it isn't an area I've ever done more than think/read about
occassionally.
Thanks Karl, these are some useful links.
I'll let you know how this tuens out!
DS
 
D

DS

DS said:
Thanks Karl, these are some useful links.
I'll let you know how this tuens out!
DS
Well Karl I found the solution......the only problem is that it's in
VB6. I need it to be in VBA and Access. I rebuilt the form and some of
the code, but is there an easy way to convert the VB6 to VBA?
Thanks
DS
 
K

Karl E. Peterson

DS said:
Well Karl I found the solution......the only problem is that it's in
VB6. I need it to be in VBA and Access. I rebuilt the form and some
of the code, but is there an easy way to convert the VB6 to VBA?

VB6 *is* VBA, for the most part, with just a few bells and whistles added. The
biggest difference, is the forms package. Otherwise, there's just a handful of
objects (App, Clipboard, Printer, etc.). IOW, it really oughta be pretty much
cut/paste -- what's the issue? (Or, where did you find the solution? I'm curious
too!)
 
D

DS

Karl said:
VB6 *is* VBA, for the most part, with just a few bells and whistles added. The
biggest difference, is the forms package. Otherwise, there's just a handful of
objects (App, Clipboard, Printer, etc.). IOW, it really oughta be pretty much
cut/paste -- what's the issue? (Or, where did you find the solution? I'm curious
too!)
Karl, Just a quick note. I got it to work. Now in Access I can check
my printer to see if its offline, and take the appropiate action. One
month off Hell.....now I'm happy!
Thank You for your input.
DS
 
K

Karl E. Peterson

DS said:
Karl, Just a quick note. I got it to work. Now in Access I can check
my printer to see if its offline, and take the appropiate action. One
month off Hell.....now I'm happy!
Thank You for your input.

Any pointers you'd care to share? This is very commonly asked.
 
D

DS

Karl said:
Any pointers you'd care to share? This is very commonly asked.
Well once again I am at loss for words! I know that this was a very
"TUFF NUT" to crack. The code and MDB file will be posted soon, so
anybody using Epson POS printers can soon access it. Whats really funny
though Karl, besides the module, I think I ended up using 20 lines of
code, one form, and one error form! Funny how you have to take the long
way around to end up with something simple. I'm now on my way to write
a Callback Function, trying to at least, to monitor the printers so that
they send a message whenever they are offline, this way you don't have
to wait untill you go to print, Just covering both ends! I wish
Microsoft would include a module like this to monitor any printer, like
you said, "It's a common question"! and it just makes sense. Well, in
any case onto the Callback, once again Thank You Karl.
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top