PC Review


Reply
Thread Tools Rate Thread

Can't get a reference to a newly added store

 
 
Water Cooler v2
Guest
Posts: n/a
 
      23rd Sep 2005
I am creating an Outlook add-in using VB.NET with VS.NET 2003. I add a
new store and then want to do something with it, but I can't seem to
get a reference to it. I put logging and found that I could get a
reference to all other stores and folders except the one I just added.

I also tried the same piece of code from within Outlook, and it worked.
I could get a valid reference for the *just* newly added store.

Here's the code I wrote in VB.NET:


Dim lSettings As Settings = GetPersistedSettings()
Dim nm As Outlook.NameSpace
Dim folders As Outlook.Folders
Dim fld As Outlook.MAPIFolder

nm = applicationObject.GetNamespace("MAPI")
nm.AddStore("Foo.pst")

Dim LngFolders As Long = nm.Folders.Count
Try
Log.Write("nm.Folders.Item(LngFolders) Is Nothing : " &
(nm.Folders.Item(LngFolders) Is Nothing))
fld = nm.Folders.Item(LngFolders)

Catch ex As Exception
Log.Write(ex.ToString & "Could not reference the newly
added Personal Folders collection.")
End Try



The code fails at the line:

Log.Write("nm.Folders.Item(LngFolders) Is Nothing : " &
(nm.Folders.Item(LngFolders) Is Nothing))


I've checked it thoroughly for the last two hours with different kinds
of logging. If I replace the LngFolders in the above line with, say, 1
like so:

Log.Write("nm.Folders.Item(1) Is Nothing : " & (nm.Folders.Item(1) Is
Nothing))

it is able to get the reference to the first (default) message store
that MAPI creates.



The same code, when modified for an Outlook macro, works from within
Outlook.


What gives?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct way to get top-level folder of newly added store (new PST file) sshock@gmail.com Microsoft Outlook VBA Programming 2 22nd Sep 2006 11:47 PM
Newly added key Mark Microsoft Access 4 3rd Dec 2005 05:11 PM
Can't get a reference to a newly added store Water Cooler v2 Microsoft Outlook 0 23rd Sep 2005 11:09 PM
Get the ID of the newly added row Imran Aziz Microsoft ADO .NET 3 28th Jul 2005 04:23 PM
cannot see newly added contacts steve christopher Microsoft Outlook Contacts 3 16th Sep 2003 10:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:09 PM.