print report from form with DoCmd

jguscs

Registered User.
Local time
Today, 13:27
Joined
Jun 23, 2003
Messages
148
Is is possible to print a report (that's already been generated and in "preview" mode) by hitting a "print" button that's on a form?

I'm trying to do this with
DoCmd.PrintOut

I realize that this command will print out the currentlyactive object, so I'm thinking I have to make the Report active first with some type of .SetFocus command, but once that .SetFocus has been run, the DoCmd.PrintOut code on the form wouldn't be run...
 
Custom menu bar...
you guys always tell me stuff I don't know how to do (which is pretty much everything, but that list is shrinking).

Anyway, what I did was save the values in various text boxes on the form to variables.
Then I closed the form with a DoCmd.
(The report becomes active by default but code in form is still running.)
Then I printed the Report (still in the code on the Form that is closed).
Then I opened the form back up with a DoCmd, and restored the text boxes' values from the variables.

Works.
 
When did I become a senior member?
Does membership have its privilages?
 
You mean you did:

DoCmd.OpenReport ("report name"), acViewPreview ' open report
DoCmd.PrintOut , , , , qty
DoCmd.close acReport, "report name", acSaveNo

Thats also what I've used, tho I do like using snapshot viewer so you can actually view the report on a form rather than opening it seperatley

CALV
 
Not quite, CALV.
It was more like:

(FROM FORM 1- the switchboard):
DoCmd.Close acForm, "FORM 1", acSaveNo
DoCmd.OpenReport "REPORT", acViewPreview, , ""
acFormPropertySettings, acWindowNormal, ""


(FROM FORM 2- the print options form):
DoCmd.Close acForm, "FORM 2", acSaveNo

It would probably be better to set the focus here to the report, just to make sure something else doesn't have it for some reason, but since the report is currently the only object open...

DoCmd.PrintOut
DoCmd.OpenForm "FORM 2", acNormal, , , acFormPropertySettings, acWindowNormal, ""

(BACK TO FORM 2- the print options form)
 
If the Report is already in Preview Mode you can also,

DoCmd.SelectObject acReport, "Report"
DoCmd.RunCommand acCmdPrint


This will give you the option of the dialog box, and should also keep the focus on the Report Preview. Wayne gave me this code and I use it quite a bit. The only thing is you need to put error handling for "Cancel" .
 
See!
I knew someone would have a better way of doing this.
Thanks, rube.
 

Users who are viewing this thread

Back
Top Bottom