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

Custom Errors

Status
Not open for further replies.

SJohnE

Technical User
Nov 3, 2009
25
US
Greetings,
I have an application that I am trying to create some error handlign. I raise an error 513 when the status in the properties of a particular file is invalid. And a nother error is raised (613) when the version of the template (xls) file isn't the same as the access database version it is expected to work with.

For some reason it is as if the err.description isn't specifically tied to either of the err.numbers becasue regardless of which one I raise the message is that of the last error I defined.

Here is the code that defines my errors:
Err.Number = vbObjectError + 513 'Invalid Template Status
Err.Source = "EPSI Auto Open"
Err.Description = "Invalid Template Satus." & vbCrLf & vbCrLf & _
"The EPSI Tag Template has an invalid" & vbCrLf & _
"or missing status in its file properties." & vbCrLf & vbCrLf & _
"It must be one of the following:" & vbCrLf & _
"Dev, Test, Prod, or Pub"

Err.Number = vbObjectError + 613 'Invalid Template version
Err.Source = "EPSI Auto Open"
Err.Description = "Versions out of Sync." & vbCrLf & vbCrLf & _
"The EPSI Template version number does not match" & vbCrLf & _
"the verion number of the EPSI Software." & vbCrLf & vbCrLf & _
"Make sure you are using the approved version of the template." & vbCrLf & _
"The approved version resides in the folder with the EPSI software."

I raise the error with:
Select Case Stat$
Case Is = "Dev"
SWPath$ = DevDir
Case Is = "Test"
SWPath$ = TstDir
Case Is = "Prod"
SWPath$ = ProdDir
Case Is = "Pub"
SWPath$ = Published
Case Else
Err.Raise Number:=vbObjectError + 513
End Select

I handle the error like this:
Clean_Up:
If Not IsNull(db) Then
db.Close
End If
Set ws = Nothing
Set db = Nothing
Set rsWD = Nothing
Set rsV = Nothing
If errflag = True Then
Application.Quit
End If
errflag = Empty
Exit Sub

ErrorHndlr:
MsgBox Err.Number 'Troubleshooting only
If Err.Number <> 0 Then
'Case Is = 53
' MsgBox "You must use the template that resides with the EPSI software.", vbCritical + vbOKOnly, _
' "TEMPLATE ERROR"
' db.Close
MsgBox Err.Number - vbObjectError & " " & Err.Source & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & SWPath$ & vbCrLf & vbCrLf & _
"If you need assistance contact Acquisiton Automation (BPS)", vbCritical + vbOKOnly, "ERROR"
Err.Clear
errflag = True
End if
GoTo Clean_Up

S J E
If I am not learning, then I am coasting, if I am coasting I must be going down hill.
 
The problem seems to be in the code that define your errors as I can't see any conditional.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
the message is that of the last error I defined

Try coding Err.Clear before you raise a new error.


Les temps sont durs pour les reveurs.
 
PHV,
Thanks for your comments, actually the first thing the application does is run the routine that defines the errors, so that the constant (vbobjecterror) has all the errors already added to it. The conditional is in the raising of the error, when an appropriate Status is not detected the error is raised.

genomom,
That was the problem is that I wasn't clearing the error after handling it. I added Err.Clear in my code at end of CleanUp just before the exit sub and that seemed to work.

Clean_Up:
If Not IsNull(db) Then
db.Close
End If
Set ws = Nothing
Set db = Nothing
Set rsWD = Nothing
Set rsV = Nothing
If errflag = True Then
err.clear
Application.Quit
End If
errflag = Empty
Exit Sub

Thank you Both for your help!!


S J E
If I am not learning, then I am coasting, if I am coasting I must be going down hill.
 
I added Err.Clear in my code at end of CleanUp just before the exit sub and that seemed to work.

YAY!!
[cheers]

Les temps sont durs pour les reveurs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top