ralph
10/5/2011 3:52:00 AM
On Tue, 04 Oct 2011 19:48:57 -0400, Marv <NoBdy@columbus.rr.com>
wrote:
>On 10/4/2011 7:38 PM, Michael Cole wrote:
>> Marv expressed precisely :
>>> Why would the following not result in an error condition. I want to
>>> determine if the default printer is on line before I do the actual
>>> printing. When the default printer is a Canon iP2600 it does cause the
>>> product a warning message from Windows, but does not cause a branch to
>>> the tag TrapError in VB. If the default printer is a Brother HL-5370W
>>> printer nothing is generated.
>>>
>>> Private Sub TestPrinter
>>>
>>> on error goto TrapError
>>> printer.print "": printer.EndDoc
>>> exit sub
>>> TrapEError:
>>> stop
>>> End Sub
>>
>> Because there is no error in VB. VB has successfully sent the document
>> to the printer queue. It has done what it was asked to do. What happens
>> after that is not its problem.
>>
>
>OK,I can see the logic in that. Is there a means of determining if the
>printer is available in VB?
There can be a few nuances (surprises? <g>) with the "default
printer", several ways to go about finding it and what other printers
might be available. (I'll let others fill in the details. <g>)
However, in general the current default printer is the one the Printer
object will "default" to. ..
Dim sTemp As String
With Printer
Debug.Print "Current (Default) Printer is " & .DeviceName
Debug.Print "Current Port is " & .Port
End With
Here is another way via the Printers collection ...
Dim vInfo
Dim iDefaultIndex As Integer
For Each vInfo In Printers
' Add printer name and port to a ListBox
ListBox1.AddItem vInfo.DeviceName & " Port " & vInfo.Port
' Check for default printer
if vInfo.DeviceName=Printer.DeviceName Then
iDefaultIndex = ListBox1.NewIndex
Next
' highlight the default
lstPrinter.ListIndex = iDefaultIndex
You can also read the registery.
The above usually works, but trouble can be brewing if the user is
using other utilities, if your application is fiddling with the
Printer object in more than one location, or if using the Common
Dialog at the same time... etc, etc.
-ralph