nodata event

  • Thread starter Thread starter kim
  • Start date Start date
K

kim

When the nodata event happens I want to dispaly a message
box, then close the report. I find that the message box
works fine but I get an error when I try to do a
docmd.close.

Any Ideas?
 
Kim,
Code the Report's OnNoData event:
MsgBox "There are nor records returned for this report."
Cancel = True

If you get a 2501 error, code the click event of the Form's command button
used to open the report:

On Error GoTo Err_Handler

DoCmd.OpenReport "ReportName", acViewPreview

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error " & Err.Number
End if
Resume Exit_This_Sub
 
Hi Kim

What is the error you get? Is it "The OpenReport action was cancelled..."?

If so, then it is coming from the code where you call DoCmd.OpenReport. It
is simply reporting the fact that the report's Open event was cancelled, in
case you want to take any special action. You need to modify your error
handler to ignore error number 2501. For example:

On Error Goto ProcErr
...
DoCmd.OpenReport "MyReport", ...
...
ProcEnd:
Exit Sub
ProcErr:
If Err = 2501 then Resume ProcEnd
MsgBox Err.Description
Resume ProcEnd

--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
 
Back
Top