Array Index Out Of Bounds

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm running into a strange problem with Outlook when I run the following
code.

Sub Item_PropertyChange(ByVal Name)

If (Name = "To") Then

Dim oCopiedItem
Set oCopiedItem = Item.Copy

' do stuff with oCopiedItem object

End If

End Sub


When I add a recipient to the TO field, the code works fine. When I delete
that same recipient from the TO field leaving it blank, I get an "Array Index
Out of Bounds" error.

This code is on the main email form - but I have also put the same code on a
custom form and have the same problem.

Has anyone run into this issue before?
 
Hi Jim,

you don´t show us the import part of your code :-)

Err.no 9 means e.g. you try to delete Recipients(2) but there is no
Recipients(2).

I guess you try to delete Recipients.Item(0) but any Items collection is
1-based. That means the first Item has always the index = 1.
 
Thanks,

The reason why I left of the 'important' part of the code, is that just
doing the Item.Copy causes the issue. I've commented everything else out all
I have is

Sub Item_PropertyChange(ByVal Name)

On Error Resume Next

If (Name = "To") Then

Dim oCopy
Set oCopy = Item.Copy

End If

End Sub


Although this code does nothing but put copies of my mail item in the
outbox, after adding & removing recipients (manually by pressing the delete
key and using the addressbook) several times I get a Array Index out of
bounds error.

I reproduced it in different environments. I'm using Outlook 2002 SP2

- Jim
 
Back
Top