Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Propagation from Report back to Opening Call

Status
Not open for further replies.

spitzmuller

Programmer
May 7, 2004
98
CH
Hi out there

I have a report that - using VBA - is configured based on user input. That input is possibly invalid and then opening the report will throw an error, which I would like to intercept and then let the user know in a decent way. This is the code that I use to try to open the report:

On Error Resume Next
DoCmd.OpenReport Me.Template, acViewPreview
If Err.Number <> 0 Then 'Error has happened
MsgBox "Bummer"
End If
On Error GoTo 0

Works great in some cases. But if the error occurs in the Report_Open-Function of that report, the error does not propagete back to the DoCmd.OpenReport that started it all, instead I get a Debug-Message that I do not want the user to see.

Do I have to implement another Error-Handling in the Report-Open Function or is there a way to propagate the error back to the DoCmd.OpenReport?

Would be great If someone could help me out. Thanks in advance to this great forum Simon
 
Hi spitz,

How about placing an 'On Error' trap in the <On-Open> function that you have mentioned?

ATB

Darrylle

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
I think I would trap the error in the reports on open event - using a msgbox with some message, if necessary - the important part is to cancel the opening of the report if any errors occur

[tt]...
myExit:
exit sub
myErr:
msgbox err.description
cancel = true
resume myExit:
end sub[/tt]

What is returned if cancelled, is the runtime error 2501, which you can trap in the form.

[tt] On Error Resume Next
DoCmd.OpenReport Me.Template, acViewPreview
If Err.Number <> 0 and Err.Number <> 2501 Then 'Error has happened
MsgBox "Bummer"
err.clear
End If
On Error GoTo 0[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top