Get MapiFolder from AddressEntry

Posted on 2003-02-24
Medium Priority
Last Modified: 2012-05-04
Hi ,
I've got an AddressEntry (which refers to a Public Folder) in Outlook 2000.
How can i get a reference to the Public Folder that this AddressEntry refers
to (i.e. i would like a MAPIFolder reference? Pseudo-code would be something
similar to this

set maFolder = GetFolderfromAddressEntry(oAddressEntry.EntryID)

where maFolder would be the reference to my public folder.

Question by:ossentoo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 8009273
I think you should use Cdo to get the FolderPath of the PublicFolder AddressEntry. Then you can walk through the path using the folders collection. If you are once referenced to the folder you can get the EntryID property of the folder.

Author Comment

ID: 8014653
HI mesch, this is just a clarification of the other question i have posted.

Here is what i have tried so far, as documented in the other question (Q_20523846). Thx


When i try this:

Debug.Print recip.AddressEntry.Fields(PR_FOLDER_PATHNAME),

i get this:
Watch : - : Err : -2147221233 : Object/ErrObject : Form1.ChangeTeamMembers

Err    : Description : " [Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]" : String : Form1.ChangeTeamMembers

I have also listed all the Fields for the AddressEntry. The only field i recognise as the folder Path is:


Have you got a code sample to show me how to walk from that to the folder i want?


Accepted Solution

mesch earned 200 total points
ID: 8065307
Hey ossentoo;

I'm not sure if you are still working on the problem. I did some tests and wrote a little code in VBScript. I did that in an Outlook custom form and it works fine. You can select an AddressEntry form the GAL and the code opens a new Explorer with the focus on the public folder.

Option Explicit

Const cRootFolderName = "All Public Folders"

Sub cmdGetFolderID_Click()
'-- Declarations CDO
Dim oSession           'as MAPI.Session object
Dim oInfoStore          'as InfoStore object
Dim oRootFolder          'as MAPI Folder object
Dim oFolder               'as MAPI Folder object
Dim oRecipient           'as Recipient object
Dim oAddressEntry      'as AddressEntry object
'-- Declarations OUTLOOK
Dim oOLNS               'as NameSpace object
Dim oOLFolder          'as Outlook Folder object
Dim oOLExplorer          'as Explorer object

Dim arrFolderLevel     'Array for the different folder levels
Dim i                    'as Counter

'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ End declarations ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False
Set oRecipient = oSession.Addressbook (Nothing, "Anrufer auswählen", True, True, 0, "","","",0)
Set oAddressEntry = oRecipient(1).AddressEntry

'-- Getting the public folder InfoStore and set the RootFolder object
For Each oInfoStore In oSession.InfoStores
    Set oRootFolder =  oInfoStore.RootFolder
    If oRootFolder.Name = "IPM_SUBTREE" Then 'This is the public folder information store
      Set oRootFolder = oInfoStore.RootFolder
      Exit For
    End If
'-- Set the oFolder object on the Toplevel Folder e.g. All Public Folders
For Each oFolder in oRootFolder.Folders
  If oFolder.Name = cRootFolderName Then
    Set oFolder = oSession.GetFolder(oFolder.ID, oRootFolder.StoreID)
    Exit For
  End If
'-- Check if AddressEntry is a Public Folder
If oAddressEntry.DisplayType <> CdoForum Then 'No Public Folder
  MsgBox "Error: " & oAddressEntry.Name & " is not a Public Folder AddressEntry!", vbCritical, "Error: AddressEntry Type"
  '-- Error string "#NA" as return value
  'getFolderIDfromAddID = "#NA"
Else 'Public Folder AddressEntry
  arrFolderLevel = Split(oAddressEntry.Fields.Item(PR_EMS_AB_FOLDER_PATHNAME).Value, "\")
  For i = 0 to UBound(arrFolderLevel)
    Set oFolder = oFolder.Folders(arrFolderLevel(i))
  '-- EntryID of the Folder object as return value
  'getFolderIDfromAddID =  oFolder.ID
  MsgBox "Folders EntryID: " & oFolder.ID
  '-- Open the Folder from Addressbook
  Set oOLNS = Application.GetNameSpace("MAPI")
  Set oOLFolder = oOLNS.GetFolderFromID(oFolder.ID, oRootFolder.StoreID)
  Set oOLExplorer = oOLFolder.GetExplorer
End If

'-- kill objects
Set oOLExplorer = Nothing
Set oOLFolder = Nothing
Set oOLNS = Nothing
Set oFolder = Nothing
Set oRootFolder = Nothing
Set oAddressEntry = Nothing
Set oRecipient = Nothing
Set oSession = Nothing
End Sub

You can easy modify this code and write a function with a return value and error handling

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question