On No Data doesn't work -Access 97

  • Thread starter Thread starter Tracey
  • Start date Start date
T

Tracey

I set up a command button on a form using the wizard.
Event procedure uses "DoCmd.OpenReport".

I then set up the "On No Data" property in the report to
display a message box, then cancel = true.

The "On No Data" procedure works fine when opening the
report straight from the database window, but my users
will be using the button on the form to open the report.

Unfortunately, I get an error that the "OpenReport action
was cancelled" when I use the command button to open the
report. Error msg: "You used a method of the DoCmd
object to carry out an action in VB, but then clicked
Cancel in a dialog box."

When I click OK, it goes away, but I do not want my users
to see this error message

Any thoughts? I cannot find any Access 97 Knowledge Base
articles on "NoData" or "OnNoData".

Thanks
 
Tracey said:
I set up a command button on a form using the wizard.
Event procedure uses "DoCmd.OpenReport".

I then set up the "On No Data" property in the report to
display a message box, then cancel = true.

The "On No Data" procedure works fine when opening the
report straight from the database window, but my users
will be using the button on the form to open the report.

Unfortunately, I get an error that the "OpenReport action
was cancelled" when I use the command button to open the
report. Error msg: "You used a method of the DoCmd
object to carry out an action in VB, but then clicked
Cancel in a dialog box."

When I click OK, it goes away, but I do not want my users
to see this error message

Any thoughts? I cannot find any Access 97 Knowledge Base
articles on "NoData" or "OnNoData".

The code is working as expected. The OpenReport action _was_ cancelled. Your button
code just needs to trap for errors and ignore when the error number = 2501.

On Error GoTo ErrHandler

DoCmd.OpenReport blah blah...

Egress:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2501
'ignore
Case Else
(your normal error handling code)
End Select
Resume Egress
End Sub
 
Back
Top