Control Page Setup of a Report through Coding


L

Lamar

My office uses Access reports to print as labels using a local Dymo Label
printer. So a user clicks a button and the Access report prints as a label
with customer's address. I have ten people in my office that need to print
multiple . So for each user I create their own report/label to print to
their local Dymo printer (so that is 10 reports).

Can use VBA to control the Page Setup of a report? I just want to use one
report named "Label" that prints each user's local printer. So when user
clicks the print label button I want the following to happen the Page Setup
of the "Label" report:

Printer change to 'Dymo Label Printer'

Margins (inches):
Top - 0.058"
Bottom - 0.06"
Left - 0.023"
Right - 0.06"

Page Orientation to 'Landscape'

Paper Size to '30321 Large Address'

It does not matter who is printing the label the dimension stay the same. I
have to control this through Coding. Any help is appreciated.
 
Ad

Advertisements

J

Jack Leach

If you're in Access 2002 or later take a look at the Printer object.

http://msdn.microsoft.com/en-us/library/aa139946(office.10).aspx

That link should give you something to work with.

If you are using a version before 2002 it's much more complicated. Go to
mvps.org/access and search for PrtDevMode for the required APIs and code.

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

On second thought, if these values will always be the same regardless of
user, you can set the properties during design and save the report with those
properties set, and for this report from now on, it will have these
properties.

I *believe*, though I'm not positive, that even if the user manually changes
these settings when the report preview is open, they will still default to
the properties they were set at when designed.

So, maybe you don't need code after all. The Printer object isn't the
easiest thing the in the world to get a handle on, so if you can avoid it, by
all means, do.
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
L

Lamar

You are correct all of the properties stay the same except 'Paper Size' that
is why I wanted to try and use coding. The Print object is out of my league.
 
J

Jack Leach

I'm not familiar enough with it to try and walk you through it, but I'm sure
others here are. You might be able to google a decent tutorial on it if you
word it right.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
Ad

Advertisements

J

Jack Leach

Something along these lines (from inside the report):


Dim prtNewPrinter As Printer

'set the NewPrinter to the current printer for the report
Set prtNewPrinter = Me.Printer

'set the property
prtNewPrinter.PaperSize = "30321 Large Address"

'set the report's printer to the NewPrinter
Set Me.Printer = prtNewPrinter

'print the report...
??

Not sure how to actually print the report through code, once it's opened.
And the report needs to be opened in order to obtain and set it's printer
object. So that's how you would set the printer anyway, maybe someone else
can pitch in with how you would go about utilizing the new setting. If I
understand correctly, unless you specifically save this new printer to the
report, it should revert back to the original after this instance.

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Ad

Advertisements


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