The GetFolder method returns a Folder object from a MAPI message store.
Set objFolder = objSession.GetFolder(folderID [, storeID] )
The GetFolder method allows you to obtain any Folder object for which you know the identifier, that is, the folder's ID property.
For some message stores, you can obtain the store's root folder by supplying an empty string as the value for folderID. If the message store does not support returning its root folder, the call returns the error value CdoE_NOT_FOUND.
Note that the store's root folder differs from the IPM root folder. The store's root folder is the parent of the root folder of the the IPM subtree. The IPM subtree contains all interpersonal messages in a hierarchy of folders. Interpersonal messages are those whose message class starts with IPM, such as IPM.Note.
You can obtain the IPM root folder with the InfoStore object's RootFolder property. You can obtain the store's root folder through the IPM root folder's FolderID property.
If your application is running as a Microsoft® Windows NT® service, you cannot access the Microsoft Exchange Public Folders through the normal hierarchy because of a notification conflict. You must use the InfoStore object's Fields property to obtain the Microsoft Exchange property PR_IPM_PUBLIC_FOLDERS_ENTRYID, property tag &H66310102. This represents the top-level public folder and allows you to access all other public folders through its Folders property. For more information on Windows NT services, see the Win32® Web page Using MAPI from a Windows NT Service at http://www.microsoft.com/win32dev/mapi/mapiserv.htm.
This code fragment uses the GetFolder method to obtain a specific folder from a MAPI message store:
' from the function Session_GetFolder
' requires a global variable that contains the folder ID
' uses a global variable that contains the message store ID if present
If strFolderID = "" Then
MsgBox ("Must first set string variable to folder ID")
Exit Function
End If
If strFolderStoreID = "" Then ' maybe get root folder
Set objFolder = objSession.GetFolder(strFolderID)
Else
Set objFolder = objSession.GetFolder(folderID:=strFolderID, _
storeID:=strFolderStoreID)
End If
If objFolder Is Nothing Then
Set objMessages = Nothing
MsgBox "Unable to retrieve folder with specified ID"
Exit Function
Else
Set objMessages = objFolder.Messages
MsgBox "Folder set to " & objFolder.Name
End If