Sub Sample()
Dim outApp As New Outlook.Application
Dim outNS As Outlook.NameSpace
Dim outFdr As Outlook.MAPIFolder
Set outNS = outApp.GetNamespace("MAPI")
For Each outFdr In outNS.Folders
OMF2 outFdr
Next outFdr
End Sub
Function OMF2(F As Outlook.MAPIFolder, Optional lngLayer As Long = 0)
Dim lng As Long
'Debug.Print Space(lngLayer * 3) & f.Name
CurrentDb.Execute "Insert Into tOLK_Folders(Folder,Class,CurrentView,Description,FolderPath) Values('" & F.Name & "', '" & CStr(F.Class) & "', '" & CStr(F.CurrentView) & "', '" & F.Description & "', '" & F.FolderPath & "')"
For lng = 1 To F.Folders.Count
OMF2 F.Folders(lng), lngLayer + 1
Next lng
End Function
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY
The above example overlooks the fact that the Top Folder (When lngLayer = 0) is technically not a Mail Folder per se. It can have folders of any type created underneath it and outlook will tell you the default type is 0, which is true. Hence, when we're looking at the top of the tree it needs to be understood that that is not a mail folder but rather the highest branch in your outlook tree. Since outlook will now avail multiple .pst files to you at once, if you didn't hae this information you'd lack any way to know which PST file the information was coming from.
Hence the caveat in my previous comment. The good news is that the solution you now seek vs. the one orginaly posted requires little more than a single line of code to be added (Line 13). Basically it checks to see if you're at the top of the tree (Layer 0) and if so allows the display of the folder not withstanding the issues previously mentioned. All other branches are discriminated, if the default item type is not 0 (a mail item) then it exist the function and does not explore that branch any further.