Consulting

Results 1 to 2 of 2

Thread: Trapping errors from RowSource query

  1. #1
    VBAX Newbie
    Joined
    Sep 2010
    Posts
    3
    Location

    Trapping errors from RowSource query

    Hi folks,

    How does one trap run-time exception errors which occur as a result of RowSource settings (which were set using the Properties window in Design View)?

    I'm working with a large codebase of VBA written in Access 2003. In over 100 instances, the developer used RowSource to enter a SELECT query, from the Properties window (not at runtime), with RowSourceType = "Table/Query". I'm tasked with adding error handling throughout the code, but I can't find a way to trap errors which might happen when the RowSource query executes.

    I've considered moving the query from the Properties window into the Form Load event, setting the control's RowSource property there at runtime. But I still can't think of a way to trap it using ON ERROR, because when the RowSource query executes, VBA/Access is outside of any of my procs/functions, thus ON ERROR doesn't apply.

    If I can't trap the errors, Access will show a message box and my error logging/handling code won't run. (For example, I'm expecting some possible timeout errors on these SELECT queries.)

    Any thoughts?

    Thanks,
    Jordan

  2. #2
    VBAX Newbie
    Joined
    Sep 2010
    Posts
    3
    Location
    Fortunately, I learned the answer from someone on another MS Access forum. The Form_Error event handler can trap a form-wide error (such as one triggered when querying for RowSource) and prevent a message box, as follows:

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    MsgBox "Error trapped! " & DataErr
    ' Log the error here
    Response = acDataErrContinue ' don't show the error dialog box
    ' Response = acDataErrDisplay ' fall through, Access will show error box
    End Sub

    You don't get the description, just the error number. But it's good enough.

    Regards,
    Jordan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •