Opening a report

mcdhappy80

Registered User.
Local time
Today, 15:18
Joined
Jun 22, 2009
Messages
347
I've created form and put a button on it, and put this code in buttons on click event:

Code:
DoCmd.OpenReport "repResenje1"

I'm getting this error:

Run-time error 2501
The Open report was canceled

What is the problem here?
 
Maybe there is no data to display . . . reports won't open without data.
 
You might want to put a message box in the report's NO DATA event:

MsgBox "There is no data to display", vbInformation, "No Data"

and then in the click event to bring up the report use an error handler to deal with the 2501 error:

Code:
On Error GoTo err_handler
 
DoCmd.OpenReport "repResenje1"
 
err_handler_exit:
Exit Sub
 
err_handler:
If Err.Number <> 2501 Then
   MsgBox Err.Description, vbExclamation, "Error number: " & Err.Number
   Resume err_handler_exit
End If

And if you don't want the report to print right away, you might want to view it first. So you need to change this:
DoCmd.OpenReport "repResenje1"

to this
DoCmd.OpenReport "repResenje1", acViewPreview
 

Users who are viewing this thread

Back
Top Bottom