Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Brisbane, Queensland, Australia
    Thanked 0 Times in 0 Posts

    Error trap for a complete form (Acc 97 sr2 on 95b)

    My users are coming up against the occasional locked form due to Access97 page locking. As it happens infrequently, they forget what causes it and I get yelled for. I want to create a message box that says "Someone else has a job open close to this number which has locked the system. Please wait a little while."

    Can I write a form module level error routine that will cover the entire form or will I have to put it in each procedure?

    A bit of aircode to get me started would be most appreciated.
    "Heading for the deep end"

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Error trap for a complete form (Acc 97 sr2 on 95b)

    You can create an event handler for the Error event of a form. This event allows you to handle events at the form level.

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    ' code to handle errors goes here
    End Sub

    The event handler has two arguments:
    DataErr is the number of the error that occurred. You can get the standard error message that belongs to it by calling AccessError(DataErr).
    Response can be set by you, it specifies how Access should handle the error. It can be
    <UL><LI>acDataErrContinue - use this if you handled the error yourself; Access won't display the standard error message.
    <LI>acDataErrDisplay - use this if you didn't handle the error yourself; Access will display the standard error message.[/list]What you should do initially, is report the error number that occurs (or store it in a table). During testing, you'll find out (hopefully) which ones occur. Then use Select Case to handle these. Error numbers that are associated with record locking are (among others) 2111 and 3158.

    Code could look like this during testing:

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    MsgBox "Error " & DataErr & " occurred with description " & AccessError(DataErr)
    Response = acDataErrContinue
    End Sub

    and later on (example for illustration purposes only, adapt as needed):

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
    Case 2111, 3158
    MsgBox "Someone else has locked the system. Please wait.", vbExclamation
    Response = acDataErrContinue
    Case 2501
    ' User cancelled something - we'll silently ignore this.
    Response = acDataErrContinue
    Case Else
    ' Let Access handle the rest
    Response = acDataErrDisplay
    End Select
    End Sub

Posting Permissions

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