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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

general error trapping form?

Status
Not open for further replies.

Hfnet

IS-IT--Management
Dec 31, 2003
369
GB
I wonder if there is a way to have a form that will pop up whenever any error is encountered within access?

Sometimes I have on expression errors come up, and it would be nice to have a form pop up with the actual error code on.

Any ideas anyone?
 
Do you mean you want to display the line of code that caused the error in a form or message box? If so that could be an interesting challenge....

Ed Metcalfe.

Please do not feed the trolls.....
 
how about
Code:
MsgBox Err.Number & ": " & Err.Description

________________________________________________________
Zameer Abdulla
Help to find Missing people
Seek counsel of him who makes you weep, and not of him who makes you laugh.
 
Ah, I may have misunderstood the meaning of "error code".

Ed Metcalfe

Please do not feed the trolls.....
 
No, what I meant was that on any error received in any form or query etc, it would pop up a form so that I can show a nicer interface to users.

Currently in the mdb version I get the errors coming up correctly when some code is wrong, for example.

But when I compile the mde, users get an "OnExpression..." error which is not descriptive and sometimes takes a while to track down in the code.
 
You may be able to open a small modal form with labels on it that will display the error code and description instead of a messagebox.
You need to look for possible errors including data errors to replace your own message to it.
see the part of a sub that take care of no current record error.
Code:
.............
ErrorHandlerExit:
    Exit Sub
ErrorHandler:
    [b]If err = 3021 Then [/b]   [COLOR=green]' no current record[/color]
        [b]Resume Next[/b]
    Else
        MsgBox "Error No: " & err.Number & "; Description: " & err.Description
        Resume ErrorHandlerExit
    End If
...........
Code:
.............
ErrorHandlerExit:
    Exit Sub
ErrorHandler:
    If err = 3021 Then   [COLOR=green] ' no current record[/color]
       [b] MsgBox "No Records Available for this selection......"[/b]
    Else
        MsgBox "Error No: " & err.Number & "; Description: " & err.Description
        Resume ErrorHandlerExit
    End If
...........
Or open a small form
Code:
.............
ErrorHandlerExit:
    Exit Sub
ErrorHandler:
    If err = 3021 Then    [COLOR=green]' no current record[/color]
        [b]DoCmd.OpenForm "formName"
    forms!fromName.LabelName.Caption="Your message"
[/b]Else
        MsgBox "Error No: " & err.Number & "; Description: " & err.Description
        Resume ErrorHandlerExit
    End If
...........

hope this helps

________________________________________________________
Zameer Abdulla
Help to find Missing people
Seek counsel of him who makes you weep, and not of him who makes you laugh.
 
Thanks, I'll give it a go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top