> What modifications are needed to get the desired results?
>
[quoted text clipped - 30 lines]
> Err.Raise vbObjectError + 12345, , "Test Prob: " & CStr(i)
> End Sub
Well, you weren't really too clear on a couple things, but I *think* what
you want is this:
Sub Main()
Dim i As Integer
On Error GoTo ErrTrap
For i = 1 To 5
Test i:=i
Next
Exit Sub
ErrTrap:
Debug.Print Err.Number & " - " & Err.Description
Resume Next
End Sub
You should not be entering into your error handler routine if there's no
error.
Alternatively, I suppose you could do this:
Sub Main()
Dim i As Integer
On Error Resume Next
For i = 1 To 5
Test i:=i
If Err.Number <> 0 Then
Debug.Print Err.Number & " - " & Err.Description
Err.Clear
Else
Debug.Print Format(i, "0. ") & " - Ok"
End If
Next
End Sub
IOW, what you were doing is kind of mixing and matching 2 different error
handling techniques.

Signature
Mike
Microsoft MVP Visual Basic
Tim - 20 Jun 2007 15:33 GMT
> > What modifications are needed to get the desired results?
>
[quoted text clipped - 75 lines]
>
> - Show quoted text -
I modified it slightly to achieve a slightly different result.
Thanks for the help.
'New Desired Results
'Test Prob: 1
'Test Prob: 2
'Test Prob: 3
'Test Prob: 4
'Inside Test: 5
'No error. Iteration: 5
Sub Main()
Dim i As Integer, blnErr As Boolean
blnErr = False
On Error GoTo ErrTrap
For i = 1 To 5
blnErr = False
Test i:=i
If blnErr = False Then 'This needs to occur if No Err
Debug.Print "No error. Iteration: " & CStr(i)
End If
Next
Exit Sub
ErrTrap:
blnErr = True
Debug.Print Err.Description
Resume Next
End Sub
Sub Test(i As Integer)
If i < 5 Then
Err.Raise vbObjectError + 12345, , "Test Prob: " & CStr(i)
End If
Debug.Print "Inside Test: " & CStr(i)
End Sub
Sinna - 21 Jun 2007 07:25 GMT
>>> What modifications are needed to get the desired results?
>>> Thanks for all help.
[quoted text clipped - 105 lines]
> Debug.Print "Inside Test: " & CStr(i)
> End Sub
Just a side note (on your programming):
If blnErr = False Then
is more easily read as
If Not blnErr Then
otherwise VB interprets it this way:
if blnErr is False:
If False = False Then
False equals False so the if returns True
else
If True = False Then
True doesn't equal False so if returns False
Sinna