error trapping

  • Thread starter Thread starter libby
  • Start date Start date
L

libby

Hi
I'm having real trouble trapping this error.

I have a sub where the active printer is changed
Application.ActivePrinter = ListBox1.value

if the printer is networked then it works fine, but if it
isn't I get a run-time error 1004
Method 'ActivePrinter' of object'_Application' failed

Is there any way I can user On Error GoTo Errorhandler to
display the message "Printer Not Mapped" if this happpens?

Thanks in advance
Libby (xl97)
 
Hi

Well, there are many networked printers in our office and
I have created a form which has 5 of the most common ones
in it. When the user selects one, a label displays the
location of the printer in the office.
I've also so set it so that if the Active Printer for a
particular pc isn't in the listbox, then it's added to it.

There is a "Change" button on the form which changes the
active printer to one which the user has selected.

It all works fine if you have all the printers mapped to
your pc, but if you try and change the active printer to
one which is not mapped to your pc, then the run-time
error occurs.
I need to either map the printer (which I don't think is
possible)
or trap this error and go to an error handler which
displays an appropriate message.

The code for the Change button is
Application.ActivePrinter = listbox1.value

I can post more code if need be, but don't have it to hand
at present.
 
I think I'd just let them pick from one of their mapped printers using a builtin
dialog box:

Application.Dialogs(xlDialogPrinterSetup).Show

But if you know enough about the printers, you can connect them via your code.

I saved this example from a post in the scripting newsgroups:

Option Explicit
Sub testme02()
Dim WSH As Object
Dim PrinterPath As String
Dim PrinterDriver As String

Set WSH = CreateObject("WScript.Network")
PrinterPath = "\\printserver\printershare"
PrinterDriver = "HP LaserJet 4050 Series PS"

WSH.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WSH.SetDefaultPrinter PrinterPath

End Sub
 
On Error goto ErrHandler
Application.ActivePrinter = listbox1.value
Exit Sub
ErrHandler:
msgbox err.number & vbNewLine & _
err.Description & vbNewline & vbNewLine & _
"This printer is not available"
End Sub
 
Thanks guys!
-----Original Message-----
On Error goto ErrHandler
Application.ActivePrinter = listbox1.value
Exit Sub
ErrHandler:
msgbox err.number & vbNewLine & _
err.Description & vbNewline & vbNewLine & _
"This printer is not available"
End Sub

--
Regards,
Tom Ogilvy






.
 
Back
Top