The information in this article applies to:
SUMMARYThis code sample demonstrates how to use Active Messaging to find out how many new, unread messages have been delivered to your Inbox since the last time this code was run.
For more information about starting an Active Messaging session using the current user's default profile, please see the following article in the Microsoft Knowledge Base:
MORE INFORMATIONThis code requires a reference to the "Microsoft Active Messaging 1.1 Object Library" (Olemsg32.dll). If you are missing this file, please see the following article in the Microsoft Knowledge Base:
Copy the following code to a module: Option Explicit Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Dim objSession As MAPI.Session Sub Main() Set objSession = CreateObject("MAPI.Session") 'This example logs you into your Exchange account. 'For an example of logging onto the current user's 'default ID, see Q171422, HOWTO: Logging on to 'Active Messaging Session w/ Default Profile[mapi] objSession.Logon ("YourIDHere") Do 'Run the CheckInbox routine, then sleep 1 minute CheckInbox Sleep (60000) Loop End Sub Private Sub CheckInbox() Dim objInbox As Folder Dim objMessages As Messages Dim objMsgFilter As MessageFilter Dim objOneMessage As Message Dim i As Integer Dim iNewMessages As Integer Static dteLastItemReceived As Date 'Static variable retains 'value Set objInbox = objSession.Inbox 'Set the Inbox object Set objMessages = objInbox.Messages 'Set the messages object Set objMsgFilter = objMessages.Filter 'Set the Message Filter 'object objMsgFilter.Unread = True 'Set the filter to find 'unread messages 'Loop through the unread messages to look for new messages. For i = 1 To objMessages.Count Set objOneMessage = objMessages.Item(i) If objOneMessage.TimeReceived > dteLastItemReceived Then iNewMessages = iNewMessages + 1 End If Next i 'If there are new messages, reset dteLastItemReceived, else 'set dteLastTimeReceived to "Now" If iNewMessages > 0 Then dteLastItemReceived = objOneMessage.TimeReceived Else dteLastItemReceived = Now End If 'Report how many new messages there are MsgBox "There are " & iNewMessages & _ " new messages since the last time I checked." End Sub
REFERENCESFor additional information about Collaboration Data Objects versus Active Messaging, please see the following article in the Microsoft Knowledge Base:
Additional query words: Keywords : kbCDO110 kbVBp400 kbVBp500 |
Last Reviewed: September 14, 1999 |