Avatar of MDauphinais1
MDauphinais1
 asked on

Microsoft Access Display Print Dialog Window

I currently use this code to automatically print a certain report:

stDocName = "GroupbyAdmin"
    DoCmd.OpenReport stDocName, acNormal

How can I make the Print Dialog window (where you select your printer and settings, etc. instead of automatically printing?
Microsoft Access

Avatar of undefined
Last Comment
Leigh Purvis

8/22/2022 - Mon
Rey Obrero (Capricorn1)

the easiest way is

stDocName = "GroupbyAdmin"
    DoCmd.OpenReport stDocName, acViewPreview
will open the report in view mode

if you want to print
File >Print
SOLUTION
Leigh Purvis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
stevbe

I create custom menus using drag-n-drop of the standard buttons etc. This print button is the one that I always make sure I am using the one from the standard File / Print menu instead of the Print on the toolbar. This way they always get the dialog.
MDauphinais1

ASKER
Can I print the report without showing a preview?

ie: just use the  Docmd.Runcommand acCmdPrint command?  When I try this it is printing the form instead of the report.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Rey Obrero (Capricorn1)

you can try this

stDocName = "GroupbyAdmin"
    DoCmd.OpenReport stDocName, acViewPreview,,,acHidden
    Docmd.Runcommand acCmdPrint

Rey Obrero (Capricorn1)

but you have to handle the event when the user click the Cancel button in the print dialog
Rey Obrero (Capricorn1)

somethng like this

On Error Resume Next
Dim stDocName As String
stDocName = "GroupbyAdmin"
DoCmd.OpenReport stDocName, acViewPreview, , , acHidden
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, stDocName
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Leigh Purvis

I reckon that will still print whatever the active object is on screen.
So if you initiate this code from a form - the report will open hidden - not be visible (or hence able to receive focus) and the form will get printed.
:-(
MDauphinais1

ASKER
LPurvis is right, it keeps printing the form. I tried to use a custom toolbar instead. You know how when you go to File --> Print it displays the print dialog but if you click on the printer icon on the toolbar it automatically prints? Well, I made a custom toolbar by selecting File-->Print as the button but when I click it, it is automatically printing and not displaying the dialog box.
MDauphinais1

ASKER
Ahh, nevermind I got it. I just created a Macro for the SendKeys command and I made that the button. Now it displays the dialog.

Thanks.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Leigh Purvis

But a toolbar will help you - *if* the report is the active object only.
That's your problem - and ultimate limitation, unless (as I say) you first manipulate the active printer - then do a standard OpenReport (acViewNormal so it prints) and then set the printer back again.

Personally - I'm usualy more comfortable giving users a look at what they're about to print out report wise - unless I'm just using a report as a paper output version of a form's data - in which case, what's to decide right? :-)
Leigh Purvis

Yuk Macro.
You could make a function and call that from the toolbar.