HOWTO: Get the Unread Message Count from an Outlook FolderLast reviewed: September 29, 1997Article ID: Q171603 |
The information in this article applies to:
SUMMARYThe following code sample demonstrates how to determine the count of all unread messages on a per folder basis for all folders grouped under a specified Microsoft Outlook folder. The sample assumes that the Microsoft Outlook mail client is installed.
MORE INFORMATIONThe code below uses a recursive routine to iterate through a mail folder to produce a list of all its sub-folders and a count of corresponding unread messages. The data is then displayed in the Visual Basic Immediate Window. The code takes advantage of the UnReadItemCount property of the Outlook MAPIFolder object.
SAMPLE CODEOption Explicit
Private Sub Main() Dim olMAPI As Outlook.NameSpace Dim Folder As Outlook.MAPIFolder Const FOLDER_TO_OPEN = "Mailbox - John Doe" 'Modify as appropriate Set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI") Call PrintFolderNames(olMAPI.Folders(FOLDER_TO_OPEN), "->") Set olMAPI = Nothing End Sub Sub PrintFolderNames(tempfolder As Outlook.MAPIFolder, a$) Dim i As Integer If tempfolder.Folders.Count Then Debug.Print a$ & " " & tempfolder.Name & " "; Debug.Print tempfolder.UnReadItemCount For i = 1 To tempfolder.Folders.Count Call PrintFolderNames(tempfolder.Folders(i), a$ & "->") Next i Else Debug.Print a$ & " " & tempfolder.Name & " "; Debug.Print tempfolder.UnReadItemCount End If End Sub Keywords : vb5all vb5howto vbwin GnrlVb kbprg Technology : kbvba Version : WINDOWS:5.0 97 Platform : NT WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |