MS Access "Array Index Out of Bounds" Error

ayngalt
ayngalt used Ask the Experts™
on
I have an Access application that we've been using for years.  One of things it does is looks in an Outlook folder and pulls any new files that have been copied to the folder.  Today we started getting an error "Array index out of bounds".  When I go to debug, it highlights the following line of code:

oMsg.Attachments.Item(1).SaveAsFile "C:\Faxes\" & TheFileName

Open in new window


Any ideas of how to work around this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
It says that in oMsg.Attachments(1) are not any objects.

Maybe there came an update from Microsoft, which changed numbering.

1) Consider changing statement to: oMsg.Attachments.Item(0) ....
2) Check if the input was not changed - if the outlook message contains attachments.

Author

Commented:
As it turns out I looked in Outlook at the email that Access was looking at didn't contain an attachment.  I guess the first one in 7 years of using the application.  Possibly not having an attachment triggered the out of bounds in that it was looking for one and none was there?  Anyway, when I deleted the email without an attachment, everything started working again.
Top Expert 2010
Commented:
Change to:

If oMsg.Attachments.Count > 0 Then
    oMsg.Attachments.Item(1).SaveAsFile "C:\Faxes\" & TheFileName
End If

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial