item.parent in Favorites

C

crm0922

So it seems Folders won't return their actual "Parent" when they exist
in the Favorites folder, whether you access them there or not.

Here's some code that searches the Favorites and looks for your folder,
then returns the folder containing it. It uses a recursive function
"p_RecurseFolder". Yes, it is similar to other EntryID locating
techniques, I know I am not that original, but it works for me.

It isn't perfectly coded I'm sure, but it seems to work well. I spent
a while trying to find a solution to this that was already worked out,
so I'm hoping I can save someone else some time. I haven't heavily
tested this, but it worked last I checked.

--- code start ---

Const PFOLDER = "All Public Folders"
Const FAVORITES = "Favorites"

Function getParentFolder()
Dim myParent, myParentObj, myFolderID, myFolderPath, foundFolder

myParent = Item.Parent.Parent
Set myParentObj = Item.Parent.Parent

myFolderID = Item.Parent.EntryID

If myParent = FAVORITES Then
Set myFolderPath =
Application.GetNameSpace("MAPI").Folders(PFOLDER).Folders(FAVORITES)
Set foundFolder = p_RecurseFolder(myFolderPath, myFolderID,
Item.Parent)
Else
Set foundFolder = Nothing
End If
If Not foundFolder Is Nothing Then
Set myParentObj = Nothing
Set myFolderPath = Nothing
Set getParentFolder = foundFolder ' Return foundFolder
Else
Set myParentObj = Nothing
Set myFolderPath = Nothing
Set getParentFolder = Item.Parent.Parent ' Return
Item.Parent.Parent
End If
End Function

Function p_RecurseFolder(ByVal SearchFld, ByVal FolderID, ByVal
FolderName)
Dim tempFold, i, tempFoldCount, recurseObj, srchID, currID

Set tempFold = SearchFld.Folders
tempFoldCount = tempFold.Count
srchID = Mid( FolderID, 1, Len(FolderID) - 3 )

For i = 1 to tempFoldCount
currID = Mid( tempFold(i).EntryID, 1, Len(tempFold(i).EntryID)
- 3 )
If currID = srchID And tempFold(i) = FolderName Then
Set p_RecurseFolder = tempFold(i).Parent ' Return
tempFold(i)
Exit Function
End If

If tempFold(i).Folders.Count Then
Set recurseObj = p_RecurseFolder(tempFold(i), FolderID,
FolderName)
If Not recurseObj Is Nothing Then
Set tempFold = Nothing
Set p_RecurseFolder = recurseObj ' Return recursive
function
Exit Function
End If
End IF
Next
Set p_RecurseFolder = Nothing ' Return Nothing
End Function

--- end code ---

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top