Close Form After Clicking on command button

P

Pam

I have a form where the user enters date information and then clicks a
command button to run a report. It all works fine, except that the form for
entering the date doesn't close. So, the report shows up in the background
and I have to click the Canel button on the form or close it manually. Is
there a way to get it to close as soon as I click the button to run the
report? Thanks!
 
D

Dirk Goldgar

Pam said:
I have a form where the user enters date information and then clicks a
command button to run a report. It all works fine, except that the form
for
entering the date doesn't close. So, the report shows up in the
background
and I have to click the Canel button on the form or close it manually. Is
there a way to get it to close as soon as I click the button to run the
report? Thanks!


If the previewed report shows up in the background, I suspect the form's
PopUp or Modal property is set to Yes, or maybe you opened the form in
dialog mode. Depending on what you're doing, you might be able to change
that, so that the form could remain open, behind the report.

That said, you can close the form in the same button Click procedure that
opens the report. For example,

Private Sub cmdPreview_Click()

' Open the report.
DoCmd.OpenReport, "YourReportName", acViewPreview

' Close this form.
DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
 

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