Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Printer object Status - if printer is on or off

Status
Not open for further replies.

saraUSIT

Programmer
Jul 15, 2009
20
US
Is there a way to check the printer's status- whether it is on or off by using the printer object?
I am trying to print a report from access in VBA- but if the printer is off I don't want the code to hang (I can't do on error resume next because there is other code that I don't want it to resume on ) - but I need to know if the printer is off because I will then send the user an email letting him know that his printer was off and program was unable to print the report - at that point the program would be able to continue running ok.

 
I can give you the code for detecting and extracting the full path for each printer which is installed on a PC. You could then run the printer dialog and check for errors.
Let me know if that helps
 
Would it work if the printer is a network printer?
Also would I be able to check the printer dialog programmatically - as this application runs at night when no one is in the office and I would like it to skip that step if the printer was turned off or having problems instead of causing the program to hang and wait for someone to debug it the next day.

Thanks
 
Yes, this works for all printers, and returns not just the printer name but the full network port and path which is needed for Excel but curiously enough not for Word ! This is what the code returns on my PC

SnagIt 8 on Ne00:
PDFCreator on Ne01:
Microsoft XPS Document Writer on Ne02:
DYMO LabelWriter 400 Turbo on Ne03:
\\pc6390\Zebra TLP2844 on Ne04:
\\ptbdm1\HP18 on Ne05:
\\ptbdm1\PlanHP02 on Ne06:
\\PTBDM1\PrintToFile on Ne07:
\\ptbdm1\X101 on Ne08:
\\ptbdm1\X102 on Ne09:

Just a small point, why do you not use On Error Resume Next just for the attempted printer selection and then reset ERR to zero afterwards ?
 
Would you mind to send me the code that produces the results you dispalyed?

Also, I'm not sure how to do the reset ERR to zero that you mentioned. Would you mind to expound on that idea as well? Thank you.
 
As the printer code is long and complex I will start with the error solution.
*******************************************************
On Error Resume Next

Here you put your dodgy bit of code that may result in an error :)

Result = err.number - tells you if you have an error
err.number=0 - resets the error to zero for the rest of the code
 

Here's a way...
Code:
'...
  On error resume next
'now your error-producing code
  if err.number = 0 then
    'continue with other code
  else
    'here's what to do since 'error-producing code' produced an error

    'reset the err object
    err.clear
  end if

'turn off error trapping
  on error goto 0


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top