|
|
Up |
|
|
  |
Author: Just Plain RickJust Plain Rick Date: May 28, 2008 10:51
I am looking for code that will allow me to print to other than the default
printer. I'd like to be able to select a printer and then print to it. I
now have the XPS printer as default and then select a printer and print to
it. Any help would be helpful.
|
| |
|
| | 12 Comments |
|
  |
Author: MikeDMikeD Date: May 28, 2008 12:05
"Just Plain Rick" mybutt.com> wrote in message news:%%230eUIuOwIHA.5892@TK2MSFTNGP02.phx.gbl...
>I am looking for code that will allow me to print to other than the default printer. I'd like to be able to select a printer and
>then print to it. I now have the XPS printer as default and then select a printer and print to it. Any help would be helpful.
Look up the Printers collection in VB5's Help. This collections holds all installed printers. Any of these can be assigned to the
Printer object to print using that particular printer. Here's an example. Start a new project and add a ListBox to Form1.
Option Explicit
Private Sub Form_Click()
Dim oPrinter As Printer
For Each oPrinter In Printers
If List1.Text = oPrinter.DeviceName Then
Exit For
End If
Next
If Not oPrinter Is Nothing Then
Set Printer = oPrinter
Printer.Print "This is a test"
Printer.EndDoc
End If
End Sub
|
| Show full article (1.18Kb) |
|
| | no comments |
|
  |
Author: Mike WilliamsMike Williams Date: May 28, 2008 12:06
"Just Plain Rick" mybutt.com> wrote in message
news:%%230eUIuOwIHA.5892@TK2MSFTNGP02.phx.gbl...
> I am looking for code that will allow me to print to other
> than the default printer. I'd like to be able to select a printer
> and then print to it. I now have the XPS printer as default
> and then select a printer and print to it. Any help would be
> helpful.
There are all sorts of different ways of doing what you want. Almost all of
them (except one) have limitations of various kinds, and the simplest
methods have the most limitations. Much depends on exactly what you want to
do. For simple printing tasks you can use the VB CommonDialog Control to
allow your user to select a printer. Try the following example on a Form
containing one Command Button and one CommonDialog Control (if you cannot
see a CommonDialog Control in your toolbox then use the Project / Components
menu and scroll down to and place a tick against Microsoft CommonDialog
Control).
Option Explicit
|
| Show full article (1.24Kb) |
| no comments |
|
  |
Author: Jeff JohnsonJeff Johnson Date: May 28, 2008 12:23
"Mike Williams" whiskyandCoke.com> wrote in message
news:%%23N4esXPwIHA.4952@TK2MSFTNGP05.phx.gbl...
> For simple printing tasks you can use the VB CommonDialog Control to allow
> your user to select a printer.
MAJOR WARNING: in order for this to work, you have to allow the dialog to
set (i.e, CHANGE) the default printer for the entire computer. This
"side-effect" is not what most users will expect and therefore I highly
recommend against doing it. If you're in the mood, search this group on
Google for old posts by me which contain the following keywords: "printer vb
common dialog sucks."
|
| |
| no comments |
|
  |
Author: Mike WilliamsMike Williams Date: May 28, 2008 13:31
"Jeff Johnson" wrote in message
news:8-udnX_zY9ulLKDVnZ2dnUVZ_hadnZ2d@posted.datapex...
> MAJOR WARNING: in order for this to work, you have
> to allow the dialog to set (i.e, CHANGE) the default printer
> for the entire computer. This "side-effect" is not what most
> users will expect and therefore I highly recommend against
> doing it.
Agreed. That is why I mentioned in my own response that there were various
methods available, and that is why I said, "almost all of them (except one)
have limitations of various kinds, and the simplest methods have the most
limitations". The method I posted was the simplest of all, as I mentioned in
my response, and it therefore has the most limitations, the "changing the
default printer" being principle amongst them. But it is a "starter" for the
OP, which is more than you have given him! Believe me, I can post lots and
lots of methods of driving printers from VB6, some of which are quite
complex, but from the tone of the OP's message I think he might not yet be
quite ready for many of them. Perhaps you might like to post your own
preferred method?
Mike
|
| |
| no comments |
|
  |
Author: Jeff JohnsonJeff Johnson Date: May 28, 2008 13:45
"Mike Williams" whiskyandCoke.com> wrote in message
news:Og8wNHQwIHA.1236@TK2MSFTNGP02.phx.gbl...
>> MAJOR WARNING: in order for this to work, you have
>> to allow the dialog to set (i.e, CHANGE) the default printer
>> for the entire computer. This "side-effect" is not what most
>> users will expect...
|
| Show full article (1.38Kb) |
| no comments |
|
  |
Author: Mike WilliamsMike Williams Date: May 28, 2008 20:44
"Jeff Johnson" wrote in message
news:6KGdnX3H94bFWaDVnZ2dnUVZ_vudnZ2d@posted.datapex...
> I'm not saying it doesn't work, I just don't think that
> method should be brought up without spelling out
> what I consider to be a huge caveat.
Agreed, which is why I told the OP that almost all VB printing methods have
limitations of various kinds, and that the simplest methods have the most
limitations. I then went on to post the simplest of them all, just as a
starter for the OP, on the assumption that he would very quickly discover
the major limitation of that specific method and would post back for more
help. That's how the learning process works best.
> And my preferred method is to roll my own select-a-printer
> dialog, for reference.
Yes. That's another simple method which the OP might like to consider. But
there are lots of limitations with that method as well, so when you post it
for the OP perhaps you might like to point some of those limitations out to
him.
Mike
|
| |
| no comments |
|
  |
Author: Just Plain RickJust Plain Rick Date: May 29, 2008 10:30
Thanks for the comments. All were helpful. I originally wanted a nice
interface like the commondialog but I didn't like to way it changed the
default printer. I can now try to create a class using the printers
collection. Something for the future.
"Mike Williams" whiskyandCoke.com> wrote in message
news:%%23hSOB5TwIHA.5520@TK2MSFTNGP06.phx.gbl...
> "Jeff Johnson" wrote in message
> news:6KGdnX3H94bFWaDVnZ2dnUVZ_vudnZ2d@posted.datapex...
>
>> I'm not saying it doesn't work, I just don't think that
>> method should be brought up without spelling out
>> what I consider to be a huge caveat.
>
> Agreed, which is why I told the OP that almost all VB printing methods
> have limitations of various kinds, and that the simplest methods have the
> most limitations. I then went on to post the simplest of them all, just as
> a starter for the OP, on the assumption that he would very quickly
> discover the major limitation of that specific method and would post back
> for more help. That's how the learning process works best.
> ...
|
| Show full article (1.42Kb) |
| no comments |
|
  |
Author: Mike WilliamsMike Williams Date: May 29, 2008 12:59
"Just Plain Rick" mybutt.com> wrote in message
news:%%23cthiGbwIHA.5580@TK2MSFTNGP04.phx.gbl...
> Thanks for the comments. All were helpful. I originally
> wanted a nice interface like the commondialog but I didn't
> like to way it changed the default printer. I can now try to
> create a class using the printers collection.
It is possible to use the standard Windows Print Dialog from VB and to
print to the printer selected by the user in the dialog without it in
any way interfering with or changing the default printer. Having said
that, there is nothing inherently wrong with creating your own custom
dialog using the data returned by the VB Printers Collection, but if
you would prefer to use the standard Windows dialog that people are
all used to then there are various ways of doing it. You can do it in
straight VB code if you wish, but one very simple alternative way of
doing it is to use the Micro$oft vbprndlg.dll, which you can find at
the following link:
http://support.microsoft.com/kb/322710
|
| Show full article (1.84Kb) |
| no comments |
|
  |
|
|
  |
Author: Mike WilliamsMike Williams Date: May 29, 2008 21:37
"Just Plain Rick" mybutt.com> wrote in message
news:%%23cthiGbwIHA.5580@TK2MSFTNGP04.phx.gbl...
> Thanks for the comments. All were helpful. I originally
> wanted a nice interface like the commondialog but I didn't
> like to way it changed the default printer . . . . .
Well, these last few posts of mine in this thread just don't seem to be
getting through. I'll try it without the dollar sign in Microsoft and see if
that makes any difference. Here goes ;-)
It is possible to use the standard Windows Print Dialog from VB and to print
to the printer selected by the user in the dialog without it in any way
interfering with or changing the default printer. Having said that, there is
nothing inherently wrong with creating your own custom dialog using the data
returned by the VB Printers Collection, but if you would prefer to use the
standard Windows dialog which people are used to then there are various ways
of doing it. You can do it in straight VB code if you wish, but one very
simple alternative way of doing it is to use the Microsoft vbprndlg.dll,
which you can find at the following link:
http://support.microsoft.com/kb/322710
|
| Show full article (3.57Kb) |
| no comments |
|
|
|
|