Discussion:
Walking the Inbox
(too old to reply)
Jerry West
2009-02-09 18:03:00 UTC
Permalink
I'm trying to walk through the MailItems in the Inbox like so:

Dim objItem as Outlook.MailItem
Dim objInbox As Outlook.MAPIFolder

For Each objItem in objInbox.Items

Next objItem

This always fails as objItem always equals Nothing. But when I check the
properties of objInbox in the Watch window I see 133 items are in the Inbox.
Why would this fail? Why wouldn't objItem become initialized as it steps
through the For Loop?

I'm using Outlook 2000. I cannot use a different version of Outlook. I know
this code works because I use it elsewhere. On the machine I'm testing it on
now there were, at one time, two different versions of Outlook installed. I
uninstalled each and re-installed a Outlook 2000. Could artifacts from the
previous installs be causing this issue?

JW
Ken Slovak - [MVP - Outlook]
2009-02-09 18:15:00 UTC
Permalink
That's a possibility, particularly if the MAPI*.* files are mixing versions.

It's also possible that the initial item the code is hitting isn't a mail
item but something else like a post item or meeting invitation, etc. That's
why in code like that I would declare objItem as Object and then assign it
to a MailItem object if objItem.Class = olMail.

I'd check that Inbox and if everything is a MailItem I'd exit Outlook and
make sure it was closed. Then I'd find and delete any MAPI*.* files in the
file system and reinstall or repair the Outlook installation.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Jerry West
Dim objItem as Outlook.MailItem
Dim objInbox As Outlook.MAPIFolder
For Each objItem in objInbox.Items
Next objItem
This always fails as objItem always equals Nothing. But when I check the
properties of objInbox in the Watch window I see 133 items are in the
Inbox. Why would this fail? Why wouldn't objItem become initialized as it
steps through the For Loop?
I'm using Outlook 2000. I cannot use a different version of Outlook. I
know this code works because I use it elsewhere. On the machine I'm
testing it on now there were, at one time, two different versions of
Outlook installed. I uninstalled each and re-installed a Outlook 2000.
Could artifacts from the previous installs be causing this issue?
JW
Loading...