Re: Printer-Object again
- From: "Mike Williams" <gagamomo@xxxxxxxxxxx>
- Date: 8 Aug 2006 09:43:51 -0700
"Helge Haensel" <dj1wm@xxxxxxxxxxxxxx> wrote in message
news:4jr3u7F9b4imU1@xxxxxxxxxxxxxxxxx
The code i am using is from a msg of yours from thread 'Vb
Printer Dialog Problems (VB6)' dated 29.06.2006.
Before I start, I apologise if the group ends up getting two copies of
this post. I'm having a problem with the server I use for this group
at the moment and I'm not sure whether the post went off okay or not,
so I've sent it again using Google Groups, just to make sure.
Okay. I've just tried that code on my own system and it works fine with
all printers, including the PDF995 driver. Everything works. There are
some settings in the code that do not actually make sense for the PDF
driver (for example PaperBin and Duplex settings) but those things are
caught by the On Error Resume Next stuff, so they aren't a problem. It
all works fine. On my system I can set the Windows default printer to
anything I want and then use the code to print to any other installed
printer, including to a pdf file using the PDF995 printer driver, and
it works fine, printing the pdf file correctly without messing up the
default printer at all.
WindowsXP/HE SP2, OfficeXP/Pro SP3, VB5E
Right. I didn't realise you were using VB5. There were many problems
with the VB5 printer driver (more than there are in VB6). Some of the
VB5 printer problems were fixed by the various service packs and some
were not. I've just installed my old "vanilla" version of VB5 (no
service packs) and tried the same code again. In VB5 the same code did
not work! It isn't a problem with any detail of the code, but rather a
problem with the VB5 printer object. Even a simple Set Printer
assignment does not work. It appears to work when you use the Set
printer command (if you ask for the Printer.DeviceName it will tell you
that the printer has been changed) but as soon as you actually try to
use the printer it will simply reset itself to the default. On my
standard vanilla VB5 installation this happens for all printers, not
just the PDF995 driver. For example, try the code at the end of this
message. If you start off with a specific default printer and you use
the code to change to another printer you will see that the Set printer
line actually works. However, as soon as you use Printer.Print (or
anything else really) the printer resets itself back to the default.
This happens on my own WinXP SP2 Home system using a vanilla
installation of VB5. I'm not sure if the problem was ever fixed by any
of the VB5 service packs, and I can't seem to find an old VB5 service
pack to try it with. Maybe you can check it on your own system? What
service pack do you use?
Now i am very keen for your answer and hope my problems
will not keep you to much off your businesswork.
Don't worry about it. I like problems ;-) By the way, I can write some
code for you that will definitely allow you to do what you want (select
and use any printer other than the default) and that code will
definitely work on all systems using either VB6 or VB5 with or without
service packs and it will work with all printers, including the PDF995
driver. However, such code will require you to print your stuff using
the various API functions instead of the standard VB Printer Object
methods. So, for simplicity it might be wise to check out the behaviour
of the VB Printer object using the latest VB5 service pack. Let me know
which Service Pack you are using, and if it is not the latest one then
perhaps you (or someone else here) might be able to tell us where we
can download it. The Microsoft web pages seem to be
extremely short of VB5 stuff these days! (Unless of course you also
have VB6, in which case you should use that instead of VB5).
I need an equivalent to the VB PinterObject statement
'Form7.PrintForm' because I have a form7 (overlarged
poscard size) that after positioning controls and setting
the printer param's will be printed about 300 times
with different text-contents coming from a database.
I usually advise people against dumping Forms to the printer, whatever
method they use, because of the limited resolution. I usually advise
people to instead draw their stuff directly to the printer using the
various Printer object drawing and printing methods, which are capable
of giving you a high resolution output. But if you really do want to
dump low resolution Form bitmaps to the printer then I can help you
with it. However, it would be wise to get the problem with the VB5 Set
printer method sorted out first. Try the code at the end of this
message and let me know how it behaves on your own version of VB5. If,
as I suspect, it fails to set the Printer correctly then you can try
updating to a later VB5 service pack and trying it again. If you are
still stuck after doing that then I'll help you out with the
alternative API printing method I have mentioned. Let me know how
it goes.
Is your return address working? Mine is. Otherwise
we will extend the thread here for nobodies interest.
The return address shown in my postings is a dummy (a protection
against spammers who farm the newsgroups for addresses). However, I'm
certainly prepared to let you have my real email address if you wish.
For the moment though I'd prefer to carry this thread on in the
newsgroup because there are often people who are interested in the
outcome of certain threads even if they don't actively participate in
them. I'll mail you my address as soon as I finish this message, but
(as I've said) I'd still prefer you to continue this thread in the
group, even if you decide to additionally mail me privately, just in
case there are others who are interested. For example, I'm sure there
are many people with various VB5 service packs who might like to let us
know how the sample code (below) behaves on their system. (Addendum:
I've just looked at your return address and there appears to be some
sort of "no spam" stuff in it, but since it's not in English I
can't quite make up my mind which bits to delete to correct it).
When you have checked out the sample code (below) don't worry if the
VB5 Printer Object won't work properly even with all the service packs
installed. As I've said, it will work under VB6 (if you have that) and
in any case there are other much more reliable ways of going about this
job which will work in any version of VB5 and VB6. But I'd prefer to
attempt the "service pack" fix first.
What i am missing is a choice of formatting text to be printed
and eventually some kind of param's passing as to preset
landscape/portrait, font(-size), bolt font and as to use . . .
All that stuff is fairly simple. But it's not worth bothering with at
this stage, at least not until we establish whether a VB5 service pack
will fix the specific printer object problem, because if it doesn't
(and if you are unable to use VB6 instead) then we'll have to go to the
API for our printing, which will of course require very different code
than would be required using the VB printer object. Anyway, try the
sample code below and let me know *in great detail* what you did and
what happens, and what service pack you are using.
Mike Williams (MVP - Visual Basic)
(Code sample below)
Private Sub Command1_Click()
' TEST RUN IN VB5 WITH NO SERVICE PACK
' (Works fine in VB6 - Not yet checked with VB5 with Service Pack)
Me.AutoRedraw = True ' printing to the Form is a habit of mine!
Print Printer.DeviceName & " (Original default)"
Dim p1 As Printer
For Each p1 In Printers
' substitute the name of any installed printer other than
' your default printer in the following line:
If InStr(p1.DeviceName, "Canon") <> 0 Then
MsgBox "Changing to Canon Printer"
Set Printer = p1
Print Printer.DeviceName & " (After using Set Printer)"
Exit For
End If
Next p1
Printer.Print ' Comment out this line and test again
Print Printer.DeviceName & " (On using Printer.Print) "
Print "(Even a simple Printer. Print statement causes the "
Print "VB Printer object to revert to the default in VB5!)"
Printer.EndDoc
End Sub
.
- Follow-Ups:
- Re: Printer-Object again
- From: Helge Haensel
- Re: Printer-Object again
- References:
- Printer-Object again
- From: Helge Haensel
- Re: Printer-Object again
- From: J French
- Re: Printer-Object again
- From: Helge Haensel
- Re: Printer-Object again
- From: Helge Haensel
- Re: Printer-Object again
- From: Helge Haensel
- Re: Printer-Object again
- From: J French
- Re: Printer-Object again
- From: Helge Haensel
- Re: Printer-Object again
- From: Mike Williams
- Re: Printer-Object again
- From: Helge Haensel
- Printer-Object again
- Prev by Date: Re: Printer-Object again
- Next by Date: Clearing Read-Only Attributes on a Folder? (VB6)
- Previous by thread: Re: Printer-Object again
- Next by thread: Re: Printer-Object again
- Index(es):
Relevant Pages
|