Re: Unable to enumerate Mailboxes in NON Cached Mode
Forget my last post... about the Stores ... it is a collection of
object... but starting from index = 1 so just solved my problem with error
handling on each Store item index.
> I tested both code methods (with the For...Each and For loops) here on
> Outlook 2007 in both online and cached modes and ran the code with no
> errors. I got the display name for public folders with no errors.
> Let's try a couple of tests.
> First, when you iterate the stores get each one as a Store object. Make sure
> you can do that with the public folders store and as a Store object try to
> access DisplayName. Do that instead of using those compound dot operators
> (oNS.Stores(i).DisplayName). They make it hard to see exactly where the
> error is occurring.
> Second, try getting the All Public Folders folder using
> oNS.GetDefaultFolder(olPublicFoldersAllPublicFolders) and see if you get a
> valid Folder object and if you can access its properties such as Name.
> I'm amazed that this is happening in online mode, if anything I'd expect
> some problem with cached mode rather than online mode.
> "stefanom74" <stefanom74> wrote in message
> > Hi Ken,
> > Thanks for the reply.
> > I found the problem !
> > I tried your code but it returns the same Automation Error (on "Next"
> > statement), then i tried to change the code from "for each" to a simple
> > (for
> > index=1 to oNS.Count) ... and here it is !!! The "real" error appeared
> > "Unable to connect Exchange...." while accessing to the DisplayName
> > store's
> > property (not on "Next i" statement). The error was on the "Public
> > Folders"
> > that is enumerated as store too!
> > An error handling inside the "For" will probably "solve" the problem.
> > (but why the "For Each" statement doesn't have the same behavior?)
> > This is the update code:
> > Sub TestBug()
> > Dim store As store
> > Dim oNS As Outlook.NameSpace
> > Set oNS = Application.GetNamespace("MAPI")
> > MsgBox (oNS.Stores.Count) '<- this returns 3
> > For i = 1 To oNS.Stores.Count
> > MsgBox (oNS.Stores(i).DisplayName) ' <- this returns Error on i =
> > 2
> > Next i
> > End Sub
> > Regards,
> > Stefano