[AccessD] VBA Error Trapping
Ryan W
wrwehler at gmail.com
Wed Apr 26 16:58:05 CDT 2023
Jim,
Okay. I like where this one is going. Then I don't have to keep track of
some extra variables in the err handling routine... can just use the built
in err object.
Will test tomorrow. Brain is fried for today.
On Wed, Apr 26, 2023 at 4:39 PM Jim Dettman via AccessD <
accessd at databaseadvisors.com> wrote:
>
> Err = 0
>
> On Error Resume Next
> DoCmd.OpenReport strReportName, acViewPreview, ,strWhere, acHidden
>
> If Err= 0 then
> DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, fullPath
> DoCmd.Close acReport, strReportName, acSaveNo
> ElseIf Err<>2501 then
> ' Some unknown error
> End If
>
> On Error Goto xxxxxxx ' Back to regular error handler
>
> -----Original Message-----
> From: AccessD On Behalf Of Ryan W
> Sent: Wednesday, April 26, 2023 2:30 PM
> To: Access Developers discussion and problem solving
> <accessd at databaseadvisors.com>
> Subject: [AccessD] VBA Error Trapping
>
> I've got this bit of code that opens a report in preview mode and hidden,
> if the NoData event cancels it I trap a 2501 error.
>
> The lines that come after the DoCmd.OpenReport code will continue to run
> and output the wrong data (an unfiltered report)
>
> What's the best way to avoid the next two lines that depend on the report
> to be open?
>
>
> I have something like this:
>
> With DoCmd
> lError = 0
> .OpenReport strReportName, acViewPreview, ,
> strWhere, acHidden
> If lError = 0 Then
> .OutputTo acOutputReport, strReportName,
> acFormatPDF, fullPath
> .Close acReport, strReportName, acSaveNo
> End If
> End With
>
> Err_Handler:
> if err.number = 2501 then
> lError = Err.Number
> Resume Next
> end if
>
>
> Is this considered copacetic? I tried without trapping the err.number to
> a variable, but it seems resume next resets the errorcode back to 0. Would
> it be better to Resume to a label after the .close command?
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
More information about the AccessD
mailing list