Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Index out of Bounds error

Status
Not open for further replies.

klornpallier

Technical User
Aug 28, 2002
98
GB
I have code that forwards a mail based on an Outlook item subject name in the Subfolder "Percentage Reports" and then moves the item to another directory "Migration Reports".

This works fine as long as I have an item in the "Percentage Reports" subfolder. If I dont when a new mail arrives I get and error "Array Index out of Bounds error". This is use with the rules wizard to move the Item to the "Percentage Reports" folder, My code is:

Private Sub Application_NewMail()


Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set SubFolderA = myfolder.Folders("Percentage Reports")
Set myforward = SubFolderA.Items(1).Forward
Set SubFolder = myfolder.Folders("Migration Reports")

Dim emailname$

For Each Item In SubFolderA.Items

MsgBox Left(Item.Subject, 3)
If Left(Item.Subject, 3) = "Loa" Then 'PERCENTAGE REPORTS

Open "C:\emailnamesWave 1.txt" For Input As #1

Do Until EOF(1)
Line Input #1, emailname

myforward.Recipients.Add emailname
Loop
Close #1

myforward.Send

Item.Move (SubFolder)

End If

End Sub
 
Code:
[green]'...
'[s]Set myforward = SubFolderA.Items(1).Forward[/s][/green]
Set SubFolder = myfolder.Folders("Migration Reports")

Dim emailname$

For Each Item In SubFolderA.Items
     [b]Set myforward = Item.Forward[/b]
     MsgBox Left(Item.Subject, 3)
[green]'...[/green]

Hope this helps,
CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top