Sub TestCustomError()
On Error GoTo TestCustomError_Err
Dim strName As String
strName = "aa"
If Len(strName) < 5 Then
Err.Raise number:=11111, _
Description:="Length of Name is Too Short"
Else
msgBox "You Entered " & strName
End If
Exit Sub
TestCustomError_Err:
'Display a message with the error number
'and description
msgBox "Error # " & Err.number & _
" - " & Err.Description
Exit Sub
End Sub
|