PDA

View Full Version : Solved: resume next on error within error



OTWarrior
11-28-2007, 02:54 AM
I currently am trying to use an error handler to make sure that on certain errors the fucntion is stopped, but on any other error to resume anyway despite reporting back the error.

here is the code (key line in red)

Public Function ID_TEN_T_Error()
If Err.Description = "The password is incorrect." Then
MsgBox (Err.Description & vbCrLf & Err.Source) & vbCrLf & _
"Make Sure You Have Selected The Correct File", vbCritical, "Import Failed"
DoEvents
nError = 1
ElseIf Err.Description = "The requested member of the collection does not exist." Then
nError = 1
MsgBox "Required field not found. Please make sure you have imported from an appropriate file"
Else
nError = 2
MsgBox Err.Description & vbCrLf & Err.Source & "Unknown Error ??"
If Err.Number > 0 Then Resume Next
End If
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
BrowseFile.Close SaveChanges:=wdDoNotSaveChanges
End Function

I am using a custome variable of "Browsefile" but everything else is the standard

asingh
11-28-2007, 03:10 AM
why not use a goto..with an error handler...

on error goto err_handler:
....
....
....

exit sub
error_handler:
if err.description = ..........
exit sub
else resume next

end sub

OTWarrior
11-28-2007, 03:27 AM
oops, figured it out myself, I moved the line to the actual error handler in the function.

error:
Call ID_TEN_T_Error
If nError = 2 Then Resume Next
End Sub