I'm looping through a collection of items and I'm deliberately creating an error, just to test the error handler.
The error trap works correctly for the first item in the FOR..NEXT loop, but on the second item it doesn't work and instead Outlook brings up an error message "type mismatch".
Of course I understand the error, but why doesn't the error trap work the second time around?
----------------------------------
Set ol = CreateObject("Outlook.Application")
Set myNameSpace = ol.Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.Folders("myNotes")
Dim myInteger As Integer
Dim myItems As Outlook.Items
Set myItems = myFolder.Items
For Each myitem In myItems
On Error GoTo myErrorHandler
myInteger = cint("abc")
myErrorHandler:
If Err.Number <> 0 Then
msgbox "Error handled"
End If
Next myitem
----------------------------------
The error trap works correctly for the first item in the FOR..NEXT loop, but on the second item it doesn't work and instead Outlook brings up an error message "type mismatch".
Of course I understand the error, but why doesn't the error trap work the second time around?
----------------------------------
Set ol = CreateObject("Outlook.Application")
Set myNameSpace = ol.Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.Folders("myNotes")
Dim myInteger As Integer
Dim myItems As Outlook.Items
Set myItems = myFolder.Items
For Each myitem In myItems
On Error GoTo myErrorHandler
myInteger = cint("abc")
myErrorHandler:
If Err.Number <> 0 Then
msgbox "Error handled"
End If
Next myitem
----------------------------------