report still looks for parameters when parameter form is cancelled

S

Sarahb

I have a report based on a query that gets its criteria from a form. The
report also uses the same criteria for the header using an unbound text box.
Everything is fine unless I press cancel on the form that collects the
criteria. The form shuts, but a parameter dialog box pops up looking for the
criteria for the header for the report, even though it should have been
cancelled. I am not sure where the code is wrong, is it a problem with the
cancel button on the form, or something on the report? Can anyone help please?
 
K

Ken Snell MVP

Probably a logic error in your "cancel the opening of the report" button
code -- the report apparently. Post the code that you're using.
 
M

Marshall Barton

Sarahb said:
I have a report based on a query that gets its criteria from a form. The
report also uses the same criteria for the header using an unbound text box.
Everything is fine unless I press cancel on the form that collects the
criteria. The form shuts, but a parameter dialog box pops up looking for the
criteria for the header for the report, even though it should have been
cancelled. I am not sure where the code is wrong, is it a problem with the
cancel button on the form, or something on the report?

I believe the problem is in the logic flow of the code that
opens the report and the form. If the report opens the
form, then you need to deal with the cancel in the report.
If the form opens the report, then it should be simple for
the cancel to skip opening the report.
 
S

Sarahb

Thank you for your replies. The report opens the form. The code in the
report I have used is:

Private Sub Report_Open(Cancel As Integer)
bInReportOpenEvent = True

DoCmd.OpenForm "frmdateandmonth", , , , , acDialog

bInReportOpenEvent = False
End Sub

Private Sub Report_Close()
DoCmd.Close acForm, "frmdateandmonth"
End Sub


The cancel code in the form is:

Private Sub cmdCancel_Click()
DoCmd.Close acForm, "frmdateandmonth"
End Sub

Thanks

Sarah
 
M

Marshall Barton

Sarahb said:
Thank you for your replies. The report opens the form. The code in the
report I have used is:

Private Sub Report_Open(Cancel As Integer)
bInReportOpenEvent = True

DoCmd.OpenForm "frmdateandmonth", , , , , acDialog

bInReportOpenEvent = False
End Sub

Private Sub Report_Close()
DoCmd.Close acForm, "frmdateandmonth"
End Sub


The cancel code in the form is:

Private Sub cmdCancel_Click()
DoCmd.Close acForm, "frmdateandmonth"
End Sub

And the form's OK button's code is ??? Presuming it's
Me.Visible = False

The all the report has to do is check if the form is still
open:

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmdateandmonth", , , , , acDialog
If Not CurrentProject.AllForms!frmdateandmonth.IsLoaded _
Then Cancel = True
End Sub
 
S

Sarahb

That's great - thanks for your help

Sarah

Marshall Barton said:
And the form's OK button's code is ??? Presuming it's
Me.Visible = False

The all the report has to do is check if the form is still
open:

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmdateandmonth", , , , , acDialog
If Not CurrentProject.AllForms!frmdateandmonth.IsLoaded _
Then Cancel = True
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