Re: Printing to a non-default printer
- From: Mike Williams <gagamomo@xxxxxxxxxxx>
- Date: Wed, 15 Apr 2009 01:46:35 -0700 (PDT)
On 15 Apr, 02:54, jake <pepp...@xxxxxxxxx> wrote:
Mainly I need help with the code required to write
to a printer other than the default Windows printer.
Also . . . I have an app [which prints labels] that
runs 24/7, keeping track of production . . . printing
a label with every scale hit. The PC that the app runs
on also creates reports on a different printer
throughout the day from various report applications.
Do I want to keep the report printer as the Windows
default printer and tell the Label code to print on
the label printer with every scale hit, or do I want
to do it the other way around (since the labeling app
runs 24/7)?
You don't need to do either. You can leave the default printer setting
alone and just amend the code in your Label printing app so that it
prints to the desired label printer without it altering the Windows
(User) default printer setting. Ideally the other apps you mention
(the various apps that create reports to a different printer) should
take the same approach, printing to whatever printer they want to
without altering the default printer settings.
You haven't said how you are performing your actual printing but on
the assumption that you are using the VB Printer Object then here is
some code which will do what you want (print to a specified printer
without altering the Windows default). You can do the same sort of
thing, albeit in a different way, even if you are not using the VB
Printer Object (if perhaps you are using the various API printing
routines instead) and if that is the case then post again
Anyway, on the assumption that you want to set the VB Printer Object
to a specific printer without presenting the user with a printer
dialog and without altering the Windows (User) default printer setting
(as would appear to be the case according to your explanation of what
your code is doing) then here is some code that will allow you to do
so:
Dim p1 As Printer, pName As String
pName = "HP Photosmart C5200 series"
For Each p1 In Printers
If UCase$(p1.DeviceName) = UCase(pName) Then
Set Printer = p1 ' this sets the VB Printer Object
Exit For
End If
Next p1
If the printer is on a network then you need to include the network in
pName above. For example, if I were to run the above code on my
laptop, which connects wirelessly to the HP PhotoSmart printer which
is actually installed on my desktop machine as a network printer, I
would need to change the pName code In the case of my own network)
from:
pName = "HP PhotoSmart C5200 series"
to . . .
pName = "\\GagaMoMo\HP PhotoSmart C5200 series"
You do of course need to provide an accurate name for the printer you
wish to use. If you're not sure of the correct device names for the
printers on your own system then the following will display them in a
ListBox for you:
Private Sub Command2_Click()
Dim p1 As Printer
For Each p1 In Printers
List1.AddItem p1.DeviceName
Next p1
End Sub
If I have misunderstood your question and if none of this stuff helps
you then post again.
Mike
.
- Follow-Ups:
- Re: Printing to a non-default printer
- From: jake
- Re: Printing to a non-default printer
- From: jake
- Re: Printing to a non-default printer
- References:
- Printing to a non-default printer
- From: jake
- Printing to a non-default printer
- Prev by Date: Re: Printing to a non-default printer
- Next by Date: GUI builders for Basic
- Previous by thread: Re: Printing to a non-default printer
- Next by thread: Re: Printing to a non-default printer
- Index(es):
Relevant Pages
|