Reference a sub-sub-folder in secondary PST using VBA

Hello Outlook experts,

I use the following code in Ms Access 2000 to find a sub-sub-folder in an added PST catalog, it works, but I was wondering if there might be a more efficient way to do this.


Option Explicit

Dim olApp As Outlook.Application

Public Sub GetMail()
 
' Reference: Microsoft Outlook Object Library
 
  Dim olNS As NameSpace
  Dim olFolder As MAPIFolder
 
  Set olApp = New Outlook.Application
  Set olNS = olApp.GetNamespace("MAPI")  ' open the MAPI Namespace
 
  Dim fol As MAPIFolder
  Dim subFolder As MAPIFolder
  Dim subsubfolder As MAPIFolder
 
  Dim strEntryID As String
 
  For Each fol In olNS.Folders
    Debug.Print fol.Name, fol.FolderPath
    For Each subFolder In fol.Folders
      Debug.Print "  -" & subFolder.Name, subFolder.FolderPath, subFolder.EntryID
      If subFolder.FolderPath = "\\test\Inbox\lifeonline" Then: strEntryID = subFolder.EntryID
      For Each subsubfolder In subFolder.Folders
        If subsubfolder.FolderPath = "\\test\Inbox\lifeonline" Then: strEntryID = subsubfolder.EntryID
        Debug.Print "    -" & subsubfolder.Name, subsubfolder.FolderPath, subsubfolder.EntryID
      Next
    Next
  Next

  If strEntryID = "" Then
    MsgBox "lifeonline not found"
    Exit Sub
  Else
    Set olFolder = olNS.GetFolderFromID(strEntryID)
  End If

End Sub


I was hoping I could do something as simple as:
    Set olFolder = olNS.Folders("\\test\Inbox\lifeonline")  ' error: the operation failed an object could not be found

Had a bit of a look at the .Find method but I think it only applies to Items in current folder.



Alan
LVL 26
Alan WarrenApplications DeveloperAsked:
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.

Alan WarrenApplications DeveloperAuthor Commented:
Set olFolder = olNS.Folders.Item("test").Folders.Item("Inbox").Folders.Item("lifeonline")

Alan  ":0)
0
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0

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
Ralf KlattEmployee in Civil ServiceCommented:
Hi,

@alanwarren ... however ... your little peace of code was a great help to me in some kind of a same situation ... the level where Outlook Folder / Item & Items access can get down to has really astonished me ... but there are huge ways of usage ... thanks alanwarren!


Best regards,
Raisor
0
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
Outlook

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.