[AccessD] VBA Error Trapping

Rocky Smolin rockysmolin2 at gmail.com
Wed Apr 26 16:05:59 CDT 2023


So this bit of code is in a loop? If so, can you put it into a separate sub
of maybe a function that returns true if printed, false if not?

r

On Wed, Apr 26, 2023 at 1:56 PM Ryan W <wrwehler at gmail.com> wrote:

> >it looks to me like you're opening in Preview Mode and then right away
> >sending the same report to the printer. In any event if the first Open
> >fails you don't want to resume next but exit the sub.
>
> In this case, I do want it to resume, but not export the now "unfiltered"
> PDF.  The report is failing with NoData because the ID in our database does
> not match the ID in the data they provided (assuming my user didn't
> normalize the data before hand, which is the red highlighting I mentioned
> to help accomplish that)
>
> So in the instance I'm testing, 2 ID's don't match and 1 Date/Time doesn't
> match between their data and what they hand-write for us to enter at the
> beginning of the job.  So, with the resume next and skipping over the
> OutPut to and close commands, I get 97 PDFs, instead of 100.  If I don't
> skip over those with some sort of logic, I get 100 PDFs, but 3 of them are
> unfiltered reports with 28 pages each, instead of 1 page each. (28 is the
> table size in rows from the client in this instance).
>
> Like I said, since I usually trap and exit the sub like you recommended,
> trying to resume the processed and figuring out how to handle commands that
> came after the failing command that need to be ignored (temporarily).....
> the only thing I came up with was to store the error (or set a boolean
> variable) to evaluate and skip over the two lines of code I do not want to
> run on "the loop with the 2501 error" and then reset on the next loop.
>
> Hope that's a better explanation.
>
>
>
> On Wed, Apr 26, 2023 at 3:41 PM Rocky Smolin <rockysmolin2 at gmail.com>
> wrote:
>
> > In my error handler I usually ignore 2501 because I've asked if the user
> > wants to do something and they say no and so the 2501 operation canceled
> > pops up.  They click OK, and carry on. But I have this in code where if
> > they cancel an operation. So in the error handler If Err.Num = 2501 then
> > exit sub else msgbox "Run Time Error: " & err.num & " - " & err.desc. and
> > exit sub.
> >
> > Re: the code starting with 'With DoCmd', generally have two buttons on
> the
> > form - Print and Preview. If the user wants to preview and know about
> > Ctrl-P, then that's all they ever use.
> >
> > It looks to me like you're opening in Preview Mode and then right away
> > sending the same report to the printer. In any event if the first Open
> > fails you don't want to resume next but exit the sub.
> >
> > r
> >
> >
> > On Wed, Apr 26, 2023 at 1:28 PM Ryan W <wrwehler at gmail.com> wrote:
> >
> > > Oops. Yeah. Forgot to add that into the pseudocode.
> > >
> > > Is the handling of the error and resume logic sane enough?  I usually
> > only
> > > handle errors that stop the process for the user to fix and start over.
> > > With this I want it to keep chugging along even if the report has no
> data
> > > (this is in relation to my query about fuzzy matching last week)....
> > right
> > > now I have the data loaded from the client show in a datasheet as red
> if
> > a
> > > matching ID for the work isn't found during the process. My users can
> > > choose to fix it (ideally) or ignore it (and then end up dealing with
> the
> > > missing reports with mismatched IDs after the fact).
> > >
> > >
> > >
> > > On Wed, Apr 26, 2023 at 3:08 PM Rocky Smolin <rockysmolin2 at gmail.com>
> > > wrote:
> > >
> > > > I think you need an Exit Sub right before Err_Handler:
> > > >
> > > > R
> > > >
> > > > On Wed, Apr 26, 2023 at 11:30 AM Ryan W <wrwehler at gmail.com> wrote:
> > > >
> > > > > 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
> > > >
> > > --
> > > 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
> >
> --
> 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