Opening a report from a form

S

Stephen @ ZennHAUS

I have a report that is opened from a form in Access 2003.

Two issues. The first is that whenever the report is opened, it opens in the
background rather than in the foreground. How do I force the report to open
in the foreground?

Second, on the form there are two unbound text boxes that serve as a date
range for the report. In a text box on the top of the report I use the
Forms!FormName!ControlName as part of a concatenated string to create the
text "Production Report from 01/02/2008 to 01/02/2009".

This works fine when generating the report, but when you then go to print
the report, it prints #Name instead of the text. I understand that this is
because the form requeries the data to ensure the printout includes any
updated records between generating and printing.

I had originally used Min(ReportDate) to Max(ReportDate), but now I am using
sub reports I can't seem to do that.

Cheers

Stephen @ ZennHAUS
 
J

Jeff Boyce

Stephen

If the report shows "behind" the form, I'm guessing the form is opened
"modal". Try opening it normally, then opening the report.

"... when generating the report ... " ?Do you mean when print previewing
the report?

#Name shows up when Access can't find the object named. Are you closing the
form before running (i.e., printing) the report? I use the
'criteria-on-form' approach and reports print without issue.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
S

Stephen @ ZennHAUS

Hi Jeff

Can I change the mode of the form from being Modal in code when a button is
clicked or does that property become read only while the form is open?

When I preview the report, it shows up on screen fine and the dates appear
in the text where they should be. But, when I Print from the preview, the
printout shows #Name.

Yes I am closing the form once the report is open, so when the Print button
is clicked the for that opened the report is no longer open.

Thanks

Stephen @ ZennHAUS
 
F

fredg

Hi Jeff

Can I change the mode of the form from being Modal in code when a button is
clicked or does that property become read only while the form is open?

Are you opening the report from an event on this Modal form?
If so, just make the form Not Visible when you open the report:

DoCmd.OpenReport "ReportName" acViewPreview
Me.Visible = False
When I preview the report, it shows up on screen fine and the dates appear
in the text where they should be. But, when I Print from the preview, the
printout shows #Name.

Yes I am closing the form once the report is open, so when the Print button
is clicked the for that opened the report is no longer open.

Well then, that is your problem.
You closed the form before the report printed.
Don't!

Close the Form in the Report's Close event:
DoCmd.Close acForm, "FormName"

I find it easier to open the report first.
Have the Report's Open event open the form in acDialog:
DoCmd.OpenForm "FormName", , , , , acDialog

Have a command button on the form to hide the form:
Me.Visible = False

Code the Report's Close event to close the form:
DoCmd.Close acForm, "FormName"

The Form open's when the report does. Enter your criteria. Click the
Form's Command button.
The form will hide and the report will Preview.
Whenever you then close the report (after preview or print), it will
close the form.
 
J

Jeff Boyce

Stephen

If you close the form before printing the report, when the query tries to
find the value in the form, it finds ...?!? #NAME

Don't close the form first!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
S

Stephen @ ZennHAUS

Thanks Fred. That's a very clever solution.

fredg said:
Are you opening the report from an event on this Modal form?
If so, just make the form Not Visible when you open the report:

DoCmd.OpenReport "ReportName" acViewPreview
Me.Visible = False


Well then, that is your problem.
You closed the form before the report printed.
Don't!

Close the Form in the Report's Close event:
DoCmd.Close acForm, "FormName"

I find it easier to open the report first.
Have the Report's Open event open the form in acDialog:
DoCmd.OpenForm "FormName", , , , , acDialog

Have a command button on the form to hide the form:
Me.Visible = False

Code the Report's Close event to close the form:
DoCmd.Close acForm, "FormName"

The Form open's when the report does. Enter your criteria. Click the
Form's Command button.
The form will hide and the report will Preview.
Whenever you then close the report (after preview or print), it will
close the form.
 

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