Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting Application.Printer.PaperSize

438 views
Skip to first unread message

Bob Darlington

unread,
Oct 8, 2010, 8:42:41 PM10/8/10
to
I'm trying to set a report (cheques) to print on a printer which is not the
default printer using the following code.
My intention is to include in an mde for distribution.
I can get the print run to work OK by manually selecting the Cheque printer
and paper size, but it seems to ignore the following code (even in my local
mdb).

Set Application.Printer = Application.Printers("Cheque Printer")
Application.Printer.PaperSize = acPRPSUser
Application.Printer.ItemSizeHeight = 9.35 ' also tried using twips
but made no difference - 5301.45
Application.Printer.ItemSizeWidth = 26.9 '15252.3
Application.Printer.PaperBin = acPRBNTractor
Application.Printer.BottomMargin = 0
Application.Printer.TopMargin = 0
Application.Printer.LeftMargin = 0
Application.Printer.RightMargin = 0
Application.Printer.Orientation = acPRORPortrait

I've tried running the code before opening the report and in the report
on_open event.
Running Access 2002 on Windows XP.
I can find no help for using the acPRPSUser constant, but feel that that
might be the problem.
Any ideas?

--
Bob Darlington
Brisbane


Salad

unread,
Oct 8, 2010, 9:50:31 PM10/8/10
to

Bob Darlington

unread,
Oct 9, 2010, 10:16:09 PM10/9/10
to

"Salad" <sa...@oilandvinegar.com> wrote in message
news:Q8adnePRUK31VzLR...@earthlink.com...


Salad,
Thanks for the reply, but none of the references you included cover user
defined paper sizes.
As mentioned in my original post, I can set the paper size manually, but not
through the code I posted.
--
Bob Darlington
Brisbane


Salad

unread,
Oct 10, 2010, 12:23:29 AM10/10/10
to
Bob Darlington wrote:

Here's a link
http://dbaspot.com/forums/ms-access/270419-default-use-specific-printer-label-size-2.html

The code is similar to yours. I didn't see any decimal parts for a
twips value tho you use one in your code. Maybe that is the problem.

Bob Darlington

unread,
Oct 10, 2010, 7:19:30 PM10/10/10
to

"Salad" <sa...@oilandvinegar.com> wrote in message
news:f_qdnVGY2JNfoizR...@earthlink.com...


Thanks Salad.
That was the code I used to build my attempt.
I tried removing the decimal points as you suggested without any luck.

Salad

unread,
Oct 10, 2010, 7:35:48 PM10/10/10
to

I doubt tractor feed programs have top or bottom margins but maybe right
and left margins need a value > 0.

Set it manually (it prints correctly, right?). What happens if you did
something like


Set Application.Printer = Application.Printers("Cheque Printer")

msgbox Application.Printer.ItemSizeWidth & _
Application.Printer.PaperBin & vbnewline & _
Application.Printer.BottomMargin & vbnewline & _
Application.Printer.TopMargin & vbnewline &_
Application.Printer.LeftMargin & vbnewline &_
Application.Printer.RightMargin & vbnewline &_
Application.Printer.Orientation & vbnewline &_
Application.Printer.PaperSize
and get the current settings?

Step thru the code as well if needed.

Bob Darlington

unread,
Oct 10, 2010, 10:22:32 PM10/10/10
to

--
Bob Darlington
Brisbane


"Salad" <sa...@oilandvinegar.com> wrote in message

news:RfednRBR9bxI0C_R...@earthlink.com...

Salad,
I appreciate your perseverance.
I changed the code to:


Application.Printer = Application.Printers("Cheque Printer")
Application.Printer.PaperSize = acPRPSUser

Application.Printer.ItemSizeHeight = 5301
Application.Printer.ItemSizeWidth = 15252
Application.Printer.PaperBin = acPRBNTractor
Application.Printer.BottomMargin = 1
Application.Printer.TopMargin = 1
Application.Printer.LeftMargin = 1
Application.Printer.RightMargin = 1
Application.Printer.Orientation = acPRORPortrait

MsgBox Application.Printer.ItemSizeWidth & vbNewLine & _
Application.Printer.ItemSizeHeight & vbNewLine & _
Application.Printer.PaperBin & vbNewLine & _
Application.Printer.BottomMargin & vbNewLine & _
Application.Printer.TopMargin & vbNewLine & _
Application.Printer.LeftMargin & vbNewLine & _
Application.Printer.RightMargin & vbNewLine & _
Application.Printer.Orientation & vbNewLine & _
Application.Printer.PaperSize

With the following result:
15252
5301
8
1
1
1
1
1
256

So it is accepting the new values, but not using them when I subsequently
open the report (in Preview or normal).
Whilst I want to be able to use this in a distributed mde, this testing is
still being done in the mdb, so the mde is not the problem (yet).
For testing purposes, the 'Cheque' report I am trying to print, is set in
design mode to use the specific printer 'Cheque Printer' and paper size
'A4'.
If I set the paper size to the custom for the report, it works OK in the
mdb, but when I load the mde to the client PC, it resets to A4 -hence the
need for this code.
My current work around is to load the mdb to the client, open it in TS and
reset the paper size, then make the mde on the client PC. I was hoping to
overcome this cumbersome approach.


Salad

unread,
Oct 10, 2010, 11:42:25 PM10/10/10
to
Bob Darlington wrote:


Hi Bob:

Hmmm...I was thinking that you said it worked if you set it manually.
So I think you would like to know the values when it works. Not the
above setting the values and then doing a display. I'm not sure where
you got the initial values to set them to.

Here's a link to MS's site. It's less than you have. Slightly
different. Not as many value changes.
http://support.microsoft.com/kb/284286

Bob Darlington

unread,
Oct 11, 2010, 2:36:08 AM10/11/10
to

"Salad" <sa...@oilandvinegar.com> wrote in message
news:WtWdneMDc8k-Gi_R...@earthlink.com...

Thanks again.
From that article, I changed my code to read:

Application.Printer = Application.Printers("Cheque Printer")

DoCmd.OpenReport "rCheque", 2, , "PropNum = " & gblPropNum, acHidden
Set rpt = Reports!rCheque
With rpt.Printer
.DefaultSize = False
.PaperSize = acPRPSUser
.ItemSizeHeight = 5301
.ItemSizeWidth = 15252
.BottomMargin = 0
.TopMargin = 0
.LeftMargin = 0
.RightMargin = 0
.Orientation = acPRORPortrait
.PaperBin = acPRBNTractor
End With

DoCmd.OpenReport "rCheque", 2, , "PropNum = " & gblPropNum

Still opens with paper size set to 'Letter'.
If I set the printer up manually, and check the values, I get the same as
above.
The original values were found by trial and error on the client's printer.
It prints onto preprinted cheque forms, so the measurements need to be
accurate.
So it appears to accept the correct values, but not apply them to the
report.
I've also tried changing the paper size for another report (formatted for
A4) using my default printer and paper bin settings, but it still won't
work.
Whenever I use acPRPSUser, I always get 'Letter' - even if I use A4
dimensions for .ItemSize.. properties.


David-W-Fenton

unread,
Oct 11, 2010, 12:43:13 PM10/11/10
to
Salad <sa...@oilandvinegar.com> wrote in
news:f_qdnVGY2JNfoizR...@earthlink.com:

> I didn't see any decimal parts for a
> twips value tho you use one in your code. Maybe that is the
> problem.

Twips are always whole numbers, no fractions.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

David-W-Fenton

unread,
Oct 11, 2010, 12:50:09 PM10/11/10
to
Salad <sa...@oilandvinegar.com> wrote in
news:Q8adnePRUK31VzLR...@earthlink.com:

> http://bytes.com/topic/access/answers/680582-access-printer-setting
> s http://support.microsoft.com/default.aspx?scid=kb;en-us;210283
> http://bytes.com/topic/access/answers/193041-setting-user-defined-p
> aper-sizes

The second of those links is for the old-fashioned PrtDevMode method
of controlling the printer, which is vastly more complicated and
fussy than using the new Printer object.

I also see from the first link there that each form has it's own
Printer object, and when I use the object browser, I find that every
form and report has it's own printer object. My guess is that you
need to set that instead of the Application.Printer object (though
I'd expect the form/report Printer object to inherit settings from
the Application.Printer object, though saved settings would no doubt
override the inherited properties).

So far as I can tell, these properties can be set in an MDE/ACCDE,
but obviously cannot be saved.

Where this is done, I'm not sure -- in the report's OnOpen event? Or
in code after opening the report?

Bob Darlington

unread,
Oct 11, 2010, 7:09:45 PM10/11/10
to
Thanks David.
I've taken out the decimal points and changed the code to work on the
report's printer object to no avail.
It still wants to revert to 'Letter' paper size, but I can't see where it
takes that value from.

--
Bob Darlington
Brisbane
"David-W-Fenton" <NoE...@SeeSignature.invalid> wrote in message
news:Xns9E0E829509804f9...@74.209.136.91...

Bob Darlington

unread,
Oct 11, 2010, 7:25:27 PM10/11/10
to
Further to my earlier reply, the 'Letter' setting was coming from the report
Page Setup, which I must have inadvertently reset during testing.
So the code I've posted, uses whatever page size is set in the report
design, and won't accept the new values set in the posted code.
If I manually select a custom paper size 'Cheque' (which has the same
dimensions) all works OK.

--
Bob Darlington
Brisbane
"David-W-Fenton" <NoE...@SeeSignature.invalid> wrote in message
news:Xns9E0E829509804f9...@74.209.136.91...

Bob Darlington

unread,
Oct 11, 2010, 9:20:27 PM10/11/10
to

"Salad" <sa...@oilandvinegar.com> wrote in message
news:WtWdneMDc8k-Gi_R...@earthlink.com...

Further to the above, if I change
.ItemSizeWidth = 15252
to read
.ItemSizeWidth = 5252
there is no change in the resultant layout. It still goes back to letter.
If I use .PaperSize = acPRPSEnvDL instead of acPRPSUser, it will format to
DL size.
So it appears to be ignoring the ItemSizeWidth whenever acPRPSUser is
selected.
It reads acPRPSUser as 'Letter' and ignores the rest.


David-W-Fenton

unread,
Oct 12, 2010, 3:29:16 PM10/12/10
to
"Bob Darlington" <b...@notheredpcman.com.au> wrote in
news:4cb39932$0$32441$afc3...@news.optusnet.com.au:

> I've taken out the decimal points and changed the code to work on
> the report's printer object to no avail.
> It still wants to revert to 'Letter' paper size, but I can't see
> where it takes that value from.

You know, I recently had a case where I couldn't get Word to print
on index cards to a printer that it had been working with for years
when it was using a parallel cable instead of USB. I ended up
changing a bunch of settings for the printer setup that finally
allowed me to change the paper size in Word and print successfully.

My point is simply that perhaps there's something wrong with the
configuration of this particular printer that's preventing your
coded changes from taking.

Bob Darlington

unread,
Oct 12, 2010, 6:31:12 PM10/12/10
to
Thanks David.
I tried different ports (LPT1, USB etc and even Print to File) without luck.
Still opens in 'Letter' size.

--
Bob Darlington
Brisbane
"David-W-Fenton" <NoE...@SeeSignature.invalid> wrote in message

news:Xns9E0F9D8E956ABf9...@74.209.136.90...

Salad

unread,
Oct 12, 2010, 8:30:22 PM10/12/10
to
Bob Darlington wrote:

> Thanks David.
> I tried different ports (LPT1, USB etc and even Print to File) without luck.
> Still opens in 'Letter' size.
>

How old is your printer? Troubleshooting this on the newsgroup is free
except for your time. After a while the cost of a new printer that
works would be more cost effective than working with a printer that is
obstinate.

Maybe contact your printer mfg.

Maybe see if there are newer drivers.

Bob Darlington

unread,
Oct 13, 2010, 5:59:40 PM10/13/10
to

"Salad" <sa...@oilandvinegar.com> wrote in message
news:2NOdnTlykcw9YCnR...@earthlink.com...

Good thinking. So I tried the same code with my Laser Printer and got the
same result.
The problem 'appears' to be with acPRPSUser.
ie the the following lines don't get recognised:


.DefaultSize = False
.PaperSize = acPRPSUser
.ItemSizeHeight = 5301
.ItemSizeWidth = 15252

If I use .PaperSize = acPRPSEnvDL for example, it reads that format OK but
if I use acPRPSUser with the above dimensions, it goes back to Letter each
time.

And all this is still in the mdb on my development PC - before it gets
deployed to the client.
Has anyone else used a custom printer setup successfully?

Bob Darlington
Brisbane


David-W-Fenton

unread,
Oct 14, 2010, 3:50:35 PM10/14/10
to
"Bob Darlington" <b...@notheredpcman.com.au> wrote in
news:4cb4e1a7$0$3032$afc3...@news.optusnet.com.au:

> I tried different ports (LPT1, USB etc and even Print to File)
> without luck. Still opens in 'Letter' size.

If I recall correctly, in my case, it also had something to do with
the Windows Print Spooler. With a networked printer, as opposed to
directly connected (as was the case when I encountered the problem),
I don't know if that's possible or not.

Bob Darlington

unread,
Oct 18, 2010, 2:54:34 AM10/18/10
to
"David-W-Fenton" <NoE...@SeeSignature.invalid> wrote in message
news:Xns9E11A12D0D7B2f9...@74.209.136.99...

Thanks David,
I've just tried all possible settings in that area with no luck.


atiqd...@gmail.com

unread,
Apr 7, 2017, 9:21:10 PM4/7/17
to
I have a label printing access database. in database report I want to 4"x4" page setup & mergin left=0.1", right=0.1"
please sent vb code.
mail: atiqd...@gmail.com
0 new messages