Automatically closing a query by form

kdirvin

Registered User.
Local time
Today, 12:17
Joined
Feb 13, 2011
Messages
41
Hi all,

I am using Access 2007. I am using a query by form to specify a parameter for a report (the year). The form has two controls, a combo listing the years and a button to call the report. I really want the form to close automatically once the user presses the button and calls the report, but the research I’ve done indicates that the form must stay open to “feed” the parameter to the report.

Is there any coding, ANY way to have the form close automatically and still have the report work properly? Otherwise I see myself putting a “Close Form” button on the form and I find that messy.

Thank you!
 
If the code behind your button click event looks like;
Code:
    DoCmd.OpenReport "RPT_YourReportName", acPreview
    
    DoCmd.Close acForm, "FRM_YourCalling FormName"
Your report will load based on the criteria collected from the form and then your from will be closed. The form only needs to stay open until the report has opened, once that has happened you can safely close the calling form.
 
Hi John,

I had tried this sequence of events earlier but had coded the button to call the report in normal view. Naturally Access prompted me for the parameter each time I switched views. Your answer made me realize that, duh, my button should call the report to open in Print Preview mode. This prevents the user from switching between views (unless they’re the programmer and know how to deal with it).

Thank you for your help!
 

Users who are viewing this thread

Back
Top Bottom