Can one Preview a Report from a Modal Form?

G

Guest

Hi -
I have a report I'd like to Print/Preview from a form that for various
reasons has to have qualities of a modal form. When I hit the button to
invoke the Print-Preview of the report, the Form remains in front of the
report until the form itself is closed.

I'm I missing a way to make the report preview viewable? Or do I need to
come up with some other way to prevent users from leaving the form (except
for perusing the report) without closing it? If so, any suggestions on how
that would be accomplished?

Many thanks,

Phil Freihofner
 
D

Duane Hookom

In the code that opens the report, set your form's visible property to
False. You can make it visible again when you need to see it.
 
S

SA

Phil:

To effectuate Duane's reply, here's the code you'd use, called from your
form:

Sub cmdPreviewRpt()

DoCmd.OpenReport "YourReport", acViewPreview
Me.Visible = False 'hide the modal form
DoEvents
'The following just loops and idles while the preview is open
While sysCmd(acSysCmdGetObjectState, acReport, "YourReport") =
acObjStateOpen
DoEvents
Wend
Me.Visible = True

End Sub
 
G

Guest

Hi -

Thanks for the replies. I don't know why it didn't occur to me to change the
form's properties. Maybe because it is modal, I forgot I can still change
things.

The code looks like a good dodge, to create a loop while waiting for the
report to lose focus, but I think I will also experiment with maybe just
"letting go" and writing some code to be triggered by the report closing or
losing focus to restore the modal form.

Thanks,
Phil Freihofner
 
G

Guest

For the sake of completeness, in case anyone else researching this problem
wants to see a possible solution, here is what I did and what seems to work
just fine.

On the button on my modal form (fsubDischargeMedication), calling the report:

Me.Modal = False 'So we can send focus to the report. Report will
'restore this form's modality and focus.
DoCmd.OpenReport "rptDischargeMeds", acViewPreview, , stCriteria
Me.Visible = False

On the report:

Private Sub Report_Close()
Forms("fsubdischargemedication").Visible = True
Forms("fsubDischargeMedication").Modal = True
Forms("fsubDischargeMedication").SetFocus
End Sub

Private Sub Report_Deactivate()
'GOAL: restore modality to [fsubDischargeMedication] if user
'clicks off of this report.

DoCmd.Close acReport, "rptDischargeMeds"

End Sub

This might not be the absolutely most concise, but it works. And, it allows
me to exercise my aversion to indefinitely looping code that the consumption
of cpu's that carries with it. (cf alternate solution offerred below)

Onward to the next task!

- Phil Freihofner
 

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