Outlook VBA On Error GoTo Not Working

B

Ben

Hi

We have developed a macro in Outlook, and for some reason On Error GoTo is
not working?

I have checked that the options are set to only Break on unhandled errors.

We have the code:
On Error GoTo errornext2
....... 4 lines later
errornext2:


Any advice would be much appreciated.

Thanks
B
 
B

Ben

Sorry, by not working I mean with the code below the code breaks when there
is an error at line 3.

I want it to just move to the next item in the loop.

1 For i = 1 To myItems.Count - 1
2 On Error GoTo errornext2
3 set item = items(1) 'Error: Runtime Error '13', type mismatch
4 .....
5 errornext2:
6 Next i

Thanks
B
 
J

James Franklin

Sorry, by not working I mean with the code below the code breaks when
there is an error at line 3.

I want it to just move to the next item in the loop.

1 For i = 1 To myItems.Count - 1
2 On Error GoTo errornext2
3 set item = items(1) 'Error: Runtime Error '13', type
mismatch 4 .....
5 errornext2:
6 Next i

Thanks
B
I think but am not positive since I am in Linux and can not test it.

Move the errornext2: block outside of the loop but within the
procedure/function. Use Resume next for those errors that should be
returned to the loop.
 
J

James Franklin

Sorry, by not working I mean with the code below the code breaks when
there is an error at line 3.

I want it to just move to the next item in the loop.

1 For i = 1 To myItems.Count - 1
2 On Error GoTo errornext2
3 set item = items(1) 'Error: Runtime Error '13', type
mismatch 4 .....
5 errornext2:
6 Next i

Thanks
B
I think but am not positive since I am in Linux and can not test it.

Move the errornext2: block outside of the loop but within the
procedure/function. Use Resume next for those errors that should be
returned to the loop.
 
C

Chip Pearson

When the code encounters an error, VBA is running in Error mode,
and subsequent errors cause runtime errors, regardless of your On
Error setting. You can get out of Error Mode by using a Resume,
or Resume Next statement, or getting out of the procedure
entirely.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
T

TC

"Type mismatch" means that you are trying to store a value, into a
variable of a type which can not possibly store that value. Like trying
to store the string value "abc" into an Integer variable. The way to
fix this is NOT to use an on error statement, but instead, to change
the type of one or both variables. So you need to show us how you have
"Dim" ed the variable 'item', and the array 'items'. Also, the 'set'
keyword might be inapproprate here - but it's hard to be certain,
without seinmg how you have dim'd the two variables.

HTH,
TC
 
Top