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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.