ErrorHandle (2)




'Place the Following Code in a Module:


Public Function ErrorHandler(iErrNum) As Integer
Select Case iAction
Case 5
'Invalid Procedure Call

MsgBox Error(iErrNum) & " Contact Help Desk."
iAction = 2
Case 7
'Out of memory

MsgBox "Close all unnecessary applications."
iAction = 1
Case 11
'Divide by 0

MsgBox "Zero is Not a valid value."
iAction = 1
Case 48, 49, 51
'Error in loading DLL

MsgBox iErrNum & " Contact Help Desk"
iAction = 5
Case 57
'Device I/O error

MsgBox "Insert a disk into Drive A."
iAction = 1
Case 68
'Device Unavailable

MsgBox "Device is unavailable _
(the device may Not exist or it is _
currently unavailable)."
iAction = 4
Case 482, 483
'General Printer Error

MsgBox "A general printer Error has _
occurred. Your printer may be offline."
iAction = 4
Case Else
MsgBox "Unrecoverable Error."
iAction = 5
End Select

ErrorHandler = iAction

End Function

'Place the following Code in each

'Procedure/Event/Function that you wish to

'utilize this Error Handling Code:


On Error Goto Errhandler

'Your Code Goes Here


Exit Sub
Errhandler:
Dim iErrorAction As Integer
iErrorAction = ErrorHandler(Err)

Select Case iErrorAction
Case 1
Resume
Case 2
Resume Next
'Case 3

'This procedure doesn't need case 3 which

'would resume to a line.

Case 4
Exit Sub
Case 5
End
End Select

Assumes:
The appropriate comments have been added to the
code so that you know where to place each item.
So long as you follow that the code should work
great for anyone.
Note that the Public Function Error Handler can
accept any additions concerning the expansion of
error codes. All functions/procedures/events that
use this error handler Do not need To be updated.











( errorhandle2.html )- by Paolo Puglisi - Modifica del 17/12/2023