Changing Printers of a Report before Printing

J

Johann Schwarz

Hi all !
I want to buils a form where I can adjust all my reports, so I can set
Paper, landscape and which printer I'm using even when the program is
compiled to an MDE As I have lost of reports but basically only a few
different printers in the Lan it would be much easier to do only to choose
one printer for A4, one for US Standard Papersize and one for Letter. Then
pressing a button and all printers should be adjusted to its needs. OK Thats
the idea. Some questions : It is easy to get the names of all printers in
the LAN using the Printers collection but how is this done in VBA in
MSAccess ?
2) When I want to do this in runtime does MS Access remember what I have
setted next time I'm using this mdb or do I need to set the Values everytime
when I start the program. Or in other words, is it possible to set this
Printersettings permanent to a specific report like a property of this
report, or do I need to renew them at each program start. or even everytime
I'm printing a report ?
3) How to get the values of papersize, landscape and which printer in the
net I want to use setted before printing a report. I cannot find more data
about prntDevNames in my Helpsystem they only reference to some SDK data
where I dont know how to find them .
Has anyone some codelines as an example for that structure and its usage ?
Thx in before

Johann Schwarz (senj)
 
A

Albert D.Kallal

Johann Schwarz said:
Hi all !
I want to buils a form where I can adjust all my reports, so I can set
Paper, landscape and which printer I'm using even when the program is
compiled to an MDE

Why have the user figure out, or decide if the reprot was laid out for
landscpace, or protalrly. How will the end user know this?

It seems to me the simple sotutionf or the above is to layout the reprot,
and save it...

The margins, and portraort/landscape will BE SAVED WITH the reprot. Once
done, you are home free. A user, and even a mde in the runtime will repscet
the layout you have setup.

To attempt to force, or have users make the decsiion on the layout is realy
not very workable.
As I have lost of reports but basically only a few different printers in
the Lan it would be much easier to do only to choose one printer for A4,
one for US Standard Papersize and one for Letter.

What does other commiearl packages such as accouting systems etc. do in the
above case?

The answer is rather simple: You need to be a bit more loose in terms of how
you layout the reprots, and STAY AWAY from the margings. The default margins
in ms-access is at 1 inch, and is done so that users don't tortulrn
themselves. If you leave your reprots tha way, then a4, or erurparly pagie
size, or north amaonc epage sizes will gernally NOT expaonce ANY probmes.

In a few of my cmmieical msa-cces s papion, I do have a margin size of .5
(1/2) infanch, and that PUSHING it...I likey should not have gone BELOVE .75
inch. I risked .5 inch...and not had any suport call yet.
2) When I want to do this in runtime does MS Access remember what I have
setted next time I'm using this mdb or do I need to set the Values
everytime when I start the program. Or in other words, is it possible to
set this Printersettings permanent to a specific report like a property
of this report, or do I need to renew them at each program start. or even
everytime I'm printing a report ?

As mentioned, just layout the report..and set the margins and
portrait/landscape. That is about all you can do for the zillion of
different printers out there.

So, in closing, don't get to close to the edge of the report page. And,
remember that ms-access ODES remember the margin settings and
portrait/landscape settings for each report. So, how you would want to
modify all of the margins? What happens if you have a custom margin size of
1.5...or .75 and don't want it modified? The kinds of complexity you are
brining into this is rather large. Keep it simple..and just layout your
reports to work on the kinds of printers that users will have...that is all
you can really do. This means you ALWAYS use the default printer setting for
your reports...and the results should thus work on ALL (or at least MOST
printers).

The only sane approach here is layout your report, and that report is going
to have to work for the types of printers that your end users have. To try
and modify report layouts at runtime is a loosing battle, and how will you
even know which reports need modifying..and ones that don't?

Perhaps you are struggling to get the layouts to work now? Also, in access
2000, there is a COMMON bug that the report layouts are frogotten in
ms-access (the solution is to turn off track-name autocorrect, or even
better install the sp updates that fix this bug).
 
A

Albert D.Kallal

Just to add a bit more:

I *do* in some of my applications allow users to select a printer (such as
for invoice printing).

You don't mention what version\of ms-access.

In access 2002 and later, there is a built in printer object, and it lets
you switch the printer with ease.

You can use:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

So, to save/switch, you can use:

dim strDefaultPrinter as string

' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName

' switch to printer of your choice:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

do whatever....print reports

Swtich back.

Set Application.Printer = Application.Printers(strDefaultPrinter)


If you are using a earlier versions, then you can use my lightweight printer
switch code here:

http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

So, I do often build a form that displays a list of installed printers, and
allow the user to select a printer. The above code example has such a form,
but that old example is REALLY only of use for pre-a2002 applications.

So, for special forms, or things like invoice printer, I sill do NOT save
which printer with the report (you *can* save the printer in ms-access, but
the feature is not much use for users since if they install, or purchase a
new printer..then the name changes..and your application will complain). So,
while we do switch printers in code..we STILL avoid saving the particular
printer to a given report. So, we always still set reports to use the
default printer.

Since the margins, and portrait/landscape are saved with the report, then
generally, just switching printers should do the trick if we kept the
margins fairly large in the reports.
 
J

Johann Schwarz

Hi !
My problem is a totally other one. So I need to explain a bit more. This Ms
access application has above 50 different reports and we hav a small lan
there with 4 different printers. This printers cannot be the default
printers because we need to print a bill with a tractor printer which has
three chemical copies which is a need of Austrian Tax authority. Other
documents as service Lists needed to be printed on a laser printer and
service documents needs again be printed on a color using printer. But all
this documents are printed 'at the same time' In practice when a TV is sold
in the shop, a bill is printed with three copies and in our service station
a service document is printed for the technican so he knows he has to
deliver that TV. If the technican himself sells anything in the service
thee same bill is printed on his tractorprinter in his servicestation and an
A4 information document is printed in our shop so its instantly known in the
office there, that a device was sold by a technican. This is needed for his
commission. Which is only used for that. Each Printer is on a different
PC's as a 'LPT1' printers installed so the printers needs to be written into
the reports. The tractorprinter in the servicestation is totaly another then
the tractor in the shop. The A4 Printer for documents which we need in the
shop is another one then for documents which we need in the servicestation,
you see. And printing labels e.g. is not allowed to have any margins. Some
sorts of labels are printed on A4 printer others are printed on a tractor.
Thats the situation. For the users it works fine. They dont need to think
about,they push a button and all data are saved and all needed documents are
coming out of the printers where they are needed.

But distributing a new version of the program within this firm needs me to
everytime setting all printers in every form again and again, because they
have different names from every machine as e.g
on the machine where the tractor in Shop is, its named 'EPSONPRN' but the
same device on another machine in the LAN of the office can only be adressed
as '\\MYPC\EPSONPRN' So I cannot set the printersnames on one machine and
copying a new version to another machine. I everytime have to reinstall all
this Printernames. Because the printer has another name there all the
existing things like papersize is changing to the default values (normally
A4 ) of the printer where the progarm is installed. So I also have to redo
all this size adjustments
I cannot give up that, because if not doing all this adjustments then the
tractor doesn't work properly because tractor paper is US size so its longer
then other papers. Printing single one A4 on it and you have to readjust
this printer. So its not a problem of margins its aproblem of length of
documents needs to be correct for each case which printer is needed. This is
a permanent reason for troubles for me, because the program has increased
and this was at least one of the points 1998,why I decided to never again
use MS access for a more modern program. All later programs I did in VB
where I never have all this trouble. But now our chief is querying me to get
a solution for that permanent problem, which is still unsolved, because it
doesn't have something like a setup. In all our VB programs we have a
setup, where we simple define all the printers and with one shot all reports
are as they need to be and are printed where they have to be printed. Word
and Access each program has a possibility to set the margins and all that so
it should be possible to do that in VBA too.
So my questions are still unchanged how to read out all printers names in
the LAN, or can this only be done using API calls ? BTW can API calls be
used in MS Access ?
How to set this printervalues for a specific report and is this done one
times and stored in the report then or needed to be done everytime before
printing
( then I would store the setup in the database itself and reloading the
values each time before printing.)
How to use prnDevNames structure ?
Thx for your interest

Johann Schwarz
 
J

Johann Schwarz

its msAccess application from MSAccess 1.0 and changed to the needs of MS
access 1997 then later translated to MS 2000 NO later version on most of the
machines.

I'll have a look on that
So, for special forms, or things like invoice printer, I sill do NOT save
which printer with the report (you *can* save the printer in ms-access,
but the feature is not much use for users since if they install, or
purchase a new printer..then the name changes..and your application will
complain). So,
Thats additional a point where I want to change only one entry in the
program and with one shot changing the printer for every formular which
needs that printer. For this reason I'll build Prseudo-printernames which
are connected to the reportsdata and when I then change the printer on one
report it loops which reports have the same pseudoprintername and
automatically changeing that printername in every report where this printer
was needed.

while we do switch printers in code..we STILL avoid saving the particular
printer to a given report. So, we always still set reports to use the
default printer.

So when you print three different documents on three different printers
while the user only presses one button you are doing ( Pseudocode )
Setting defaultprinter
reportA.Print
setNewDefaultprinter
reportB.Print
setOtherDefaultprinter
reportC.print

This is good but I also need to set papersize to A4 ( 210x297mm) or what we
name US size which is longer ( 210x305 mm ) How to do that then ?

Johann Schwarz
 
A

Albert D.Kallal

So my questions are still unchanged how to read out all printers names in
the LAN, or can this only be done using API calls ? BTW can API calls be
used in MS Access ?

My sample download does have a form that loads/displays the list of
printers. As mentioned, if you have a2002 or later, there is a printer
object, and you can iterate the printers collection.

As mentioned, I have several applications in which I allow users to select
what printer will be the invoice printer. This can be easily saved in a
table.

The ONLY real special cases you have is the tractor feed reports. (and a
particular forms length). You simply need to layout that repot for a dot
matrix printers. If you also need the SAME report to be send to another
printer (plan paper/laser printers), then I would create copy of the report.
The reasons for this is that this is MUCH LESS work to simply make, and
maintain a copy of the report then trying to modify all of that margin stuff
and printer layout stuff. This approach should work for each of the stations
(unless their dot matrix printers really are different).

So, the only real reason I can see the need to change printer setups is ONLY
for those special case tractor feed reports. And, if you lay them out for a
Epson printer, (and use printer fonts), then you should be able to have a
setup that works, allows you to print to different printers in one shot, and
not have to write a lot of code. For MOST of the reports, your problems of
tractor feed, and special cases does NOT apply
This is good but I also need to set papersize to A4 ( 210x297mm) or what we
name US size which is longer ( 210x305 mm ) How to do that then ?

Hum, Is the above for the laser printer, or the tractor feed? Just layout
the report for above size paper. The resulting report will actually work on
MOST printers. (the dot matrix are the special case ones).
How to use prnDevNames structure ?

If you must, (and, I would trying advoing this, ), there is documenting on
print-dev here:
http://www.mvps.org/access/reports/rpt0009.htm
 
J

Johann Schwarz

the LAN, or can this only be done using API calls ? BTW can API calls be
As I have seen your code the answer is obviously 'yes'.
My sample download does have a form that loads/displays the list of
printers. As mentioned, if you have a2002 or later, there is a printer
object, and you can iterate the printers collection.

Your sample is great for changing the default printers every time and also
for reading out what printers are there. So I can use that part to read out
printers obviously.
The MS example shows long explanations but I couldn't find the full code
anywhere. Looks as if this is no longer on the web. Do you know if some of
the MVP's has a copy of it ?

What I see is: when I'm copying the mdb from one machine to another and want
to correct the printers to the printernames as they are shown on that
machine, then I open a report in designmode. But before I can do that, a
Messagebox occures telling me the prnter is nor available and if I want to
set it to the default printer.
If I do and the default on that machine is maybe the tractor then all A4
settings will be lost it the default is the A4 all the tracktor
printersettings are lost. So I have to set Size, orientation and Printername
for each report. So I really want to automate that procedure.
As mentioned, I have several applications in which I allow users to select
what printer will be the invoice printer. This can be easily saved in a
table.
yes this is a great code for that.
The ONLY real special cases you have is the tractor feed reports. (and a
particular forms length).

yes but thats approximate 50 % of my reports.

You simply need to layout that repot for a dot
matrix printers.

The layout is done for such a printer.

If you also need the SAME report to be send to another
printer (plan paper/laser printers), then I would create copy of the
report.

This is also done in that way.
The reasons for this is that this is MUCH LESS work to simply make, and
maintain a copy of the report then trying to modify all of that margin
stuff and printer layout stuff. This approach should work for each of the
stations > (unless their dot matrix printers really are different).

But setting all printers to be the defaultprinter causes two problems. The
setup for matrix reports is : Paperfeed tractor, size 210x305 mm some
documents in landscape orientation, most are in norml orientation.

The laserprinter is all A4 ( 210x 297 ) and also some are landscape
orientated.

So to understand you correct: Do you think if I'm setting the defaultprinter
of my machine to the tractor and doing all other settings for every formular
( papersize, orientation nd paperfeed just as needed ) then storing that
reports that way I can use my list list which I'm creating to change the
defaultprinter everytime just before printing and the other values in my
reports will never change nor gone lost, because I'm not opening forms in
designmde and they
will everytime get the correct printer, because using' default printer
property doesn't entry a specific printername in the reports. Is it working
in that way.
Is all my trouble because all my reports are set to 'specific printer' and
this specific printer doesn't exist when I'm copying mdb to another machine
? Is that the real problem ?
So I would need to do: ( Pseudocode ) SaveOriginalDefaultprintername,
ReadNeededPrintername in myPrintersList , SetNewDefaultPinter , Print
Report, readNextneededPrinter in myPrinterlist, SetNewDefaultPinter Print
nextReport.... ans when finished - resetOriginalDefaultPrinter
( this would be a command where one command prints more then one different
Report on different machines )
If it works like that please tell me then I would readjust my settings all
to defaultprinter and doing my code and it should work,even in am MDE.
 
J

Johann Schwarz

Hi !
Thanks for your help it seems to work properly as much as I could test
untilnow, but there is only one point: we have WinXP and WinMe OS on the
PC's So I tried on my machine here and it didn't show any defaultprinter now
when I'm looking to the printers in the OS So I have toreset that check
near the default by hand. But as I have read your code this should be done
with the send message Broadcast. But I think it isn't a change in vin.ini
anymore, so which message needs to be broadcastet in XP and which in WinMe
system.

Johann
 
J

Johann Schwarz

HI ! ( I wrote this before, but I cannot find it in this thread, so maybe I
did something wrong as I'm not very good with this news editor.
The message was something like that:

Thx a lot, I did as your example suggested. It seems to work now. There is
only a small point. I have XP as OS and on this my defaultprinter is now no
longer signed with an check in the printers folder ( Where I can see all my
printers in the system - I dont know acactly how to name it in English ) But
I can check it if I want by hand. But it will vanish after the first print I
do. So I guess the broadcasted sendmessage in your command needs a change in
XP ?
Any hint ?

Johann Schwarz
 
A

Albert D.Kallal

The MS example shows long explanations but I couldn't find the full code
anywhere. Looks as if this is no longer on the web. Do you know if some
of the MVP's has a copy of it ?

I don't know about full code, I just pointed out some print-dev exmaples.

There is some example code in the above links...one of them leads to:
http://www.mcwtech.com/downloads.aspx

In the above, there is some sampel code that uses printDev.

As I mentned, I advoiced print-dev since I think it is a lot of work.
What I see is: when I'm copying the mdb from one machine to another and
want to correct the printers to the printernames as they are shown on that
machine, then I open a report in designmode.

As I said, in ALL CASES you do NOT want to set a default printer in the
reprot..
If I do and the default on that machine is maybe the tractor then all A4
settings will be lost it the default is the A4 all the tracktor
printersettings are lost.

Are they lost? I did not think so. I was suggesting to simply layout the
reprot, and size it untill it works ok.
(this may not work, but it is what I would try).
You simply need to layout that repot for a dot

The layout is done for such a printer.

Yes, but you still want to have the reprot set as a default printer..and not
a particlar one. I am note sure if I was clear, but my suggestion in all
cases is to NEVER set a speiciv printer in the reprots (page setup)
seetings. However, if thsoe users really do have differnt
dot maxtrix printers, and your default layout does NOT work for each of
those different dot matrix printers, then you will have to resort to using
the print-dev to set this up (or, specive printers and reprots as you have
now).

But setting all printers to be the defaultprinter causes two problems. The
setup for matrix reports is : Paperfeed tractor, size 210x305 mm some
documents in landscape orientation, most are in norml orientation.

Well, the page setup does remember portrant/landsacpe, and the margin
sizes. (if these settngs are being lost, then
perhaps you are expaice ht4e common bug outlined here).

http://support.microsoft.com/default.aspx?scid=kb;en-us;240826
Do you think if I'm setting the defaultprinter of my machine to the
tractor and doing all other settings for every formular

I not tried the above, but I was suggesting to NEVER set an actua. printer
with a reprot.
When I say defalt..I mena a default printer (I personaly use a pdf priinter
as a default).
Is all my trouble because all my reports are set to 'specific printer' and
this specific printer doesn't exist when I'm copying mdb to another
machine

Yes...that is much of your problem....is due to the above..

I mean, for some of the custom invoice printing sutff, I have a user defined
top margin setting. They can "tweak" this setting if they
purchase a differnt printer. I also experiance roller wear and tear..and
that seems to throw things out over time also. As a result, I do
have a form that lets users "setup" the top marking of the report. So, if
there printer wears, or they change the model, then they can change the top
margin to re-aline the form that they are printing on to. The code in the
reports on-open event to do this is


currTop = Nz(DLookup("topMargin", "tblTopMargin", "reportname = '" &
Me.Name & "'"), 0)
If currTop > 0 Then
Me.ReportHeader.Height = currTop * 1440
End If

In the above, I have a table called "tblTopMargin". For each reprot that
needs this setting, I make a entry into the talbe, and then
place the above code into the reprost on-open event. (notice how the above
code can be pasted into ANY repot...no hard coded names).
By chaning the height of the reprots headder...it pushes down all of the
"reprot" that
is to be printed to the printer. (I thus desing my reprots to ALWASY be a
bit high on the page..and then MOVE then down using the above code).
This way, I don't have to bother with complex print-dev code, and the top
alimgnet is saved in a table for me.
If it works like that please tell me then I would readjust my settings all
to defaultprinter and doing my code and it should work,even in am MDE.

You will have to try, but, my rule as a developer is that I NEVER set (use)
the report setting that allows you to specify a particular printer, I
ALWAYS use the default printer. (as mentioned, due to your dot matrix,
setting the reports length likely will be a issue that you have to deal
with..so, my approach might not work).

As I said, you can go hog wild with print-dev, but it is a lot of work. The
above example has only 4 lines of code..and allows me to set a value to
"push" down the report a bit for alignment purposes when a different printer
is used.

All of my advice can simply be summed up as

If you can easily avoid print-dev..then do so!! - you might not in your
case, and the top margin, and perhaps a bottom margin setting as just might
do the trick for you (and, the above works as a mde, and even with the
access runtime system)..
 
J

Johann Schwarz

Thx a lot so far. I have now done all with the dea´fault printer and it
obviously works. There is only one single and maybe simple problem: The
checks on the default printer in the systems printer-view ( where I can see
all my printers and thatone which is the default is checked normally ) this
check is gone. As I have XP on nearly every machine ( one has Win -ME )
maybe the msg broadcast doesn't proper work in XP ?
So how to do this in XP that the just active default can be seen in this
systems - printer view ?

Thanks a lot for all your great info

Johann Schwarz (senj )
 
A

Albert D.Kallal

checks on the default printer in the systems printer-view
As I have XP on nearly every machine ( one has Win -ME ) maybe the msg
broadcast doesn't proper work in XP ?


A LONG time standing bug in my code. I have not found a fix for this yet,
and since I not used the code for years (since a2002 and later
has the built in printer object).

You could ask around in the VB groups as to how to refresh the list, but I
don't have a solution handy...
 
J

Johann Schwarz

As I said, you can go hog wild with print-dev, but it is a lot of work.
The above example has only 4 lines of code..and allows me to set a value
to "push" down the report a bit for alignment purposes when a different
printer is used.

All of my advice can simply be summed up as

If you can easily avoid print-dev..then do so!! - you might not in your
case, and the top margin, and perhaps a bottom margin setting as just
might do the trick for you (and, the above works as a mde, and even with
the access runtime system)..

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.members.shaw.ca/AlbertKallal
So I did it thanks. Its interesting that I have two times tried to add a
further question here but its not appended ?? ( I'm not very good in
handling this outlook express newsreader. But its still better then that one
in MS Forum )

So my query was that the defaulprinters have changed and printing works, but
as I have XP it does no more show any defult printer then.

For common interst maybe, the command to inform the system about the change
has to be a bit changed in XP to
<code>
Call SendNotifyMessage(HWND_BROADCAST, WM_WININICHANGE, 0&,
StrPtr("Windows"))
</code>when using StrPtr function it also works in XP systems correctly
(This hint comes to me from codeguru - forum. Tested - works. )
So thx for all

Johann Schwarz (senj)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top