Closing a form when closing a report

Bryan

Registered User.
Local time
Today, 07:05
Joined
May 7, 2012
Messages
124
I have a report that I open via a form. The form contains two text boxes which define the date range of the report, so I have left the form open when running the report.

I would like to close the form when closing the report, but am encountering a code issue with the form close event:

Private Sub Report_Close()

DoCmd.Close acForm, frmWhatDates_Report, acSaveNo

End Sub

The error is a missing object name argument, so I presume there is an issue with how I have specified the name of the form to be closed. I've tried quotes as well with no success.

Thanks!
 
You need to place double quotes around the form name in your line of code:
Code:
Private Sub Report_Close()

    DoCmd.Close acForm, "frmWhatDates_Report", acSaveNo

End Sub

In your description of the issue it seems clear that the form would always be open, however, if there is any chance that the form might get closed before the report is closed, you might want to check to be sure that the form is actually open before attempting to close it so you don't get an error.

Code:
If CurrentProject.AllForms("frmWhatDates_Report").IsLoaded = True Then
    DoCmd.Close acForm, "frmWhatDates_Report", acSaveNo
End If
 
Thanks, Mr. B.

I thought I had tried double quotes, but obviously not. When I posted that I had tried quotes, I was actually thinking double quotes. I'm guessing that I inadvertently tried single quotes, which didn't work, of course.

I'm set. Thanks again!
 

Users who are viewing this thread

Back
Top Bottom