Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 849
  • Last Modified:

Get MapiFolder from AddressEntry

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.

  • 2
1 Solution
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.
ossentooAuthor Commented:
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?

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now