Microsoft KB Archive/172741: Difference between revisions
m (Text replacement - ">" to ">") |
m (Text replacement - "&" to "&") |
||
(One intermediate revision by the same user not shown) | |||
Line 38: | Line 38: | ||
== MORE INFORMATION == | == MORE INFORMATION == | ||
This code requires a reference to the | This 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: | ||
<blockquote>[[../171440|Q171440]] INFO: Where to Acquire the Collaboration Data Objects Libraries</blockquote> | <blockquote>[[../171440|Q171440]] INFO: Where to Acquire the Collaboration Data Objects Libraries</blockquote> | ||
Line 44: | Line 44: | ||
<pre class="CODESAMP">Option Explicit | <pre class="CODESAMP">Option Explicit | ||
Declare Sub Sleep Lib | Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) | ||
Dim objSession As MAPI.Session | Dim objSession As MAPI.Session | ||
Sub Main() | Sub Main() | ||
Set objSession = CreateObject( | Set objSession = CreateObject("MAPI.Session") | ||
'This example logs you into your Exchange account. | 'This example logs you into your Exchange account. | ||
'For an example of logging onto the current user's | 'For an example of logging onto the current user's | ||
'default ID, see Q171422, HOWTO: Logging on to | 'default ID, see Q171422, HOWTO: Logging on to | ||
'Active Messaging Session w/ Default Profile[mapi] | 'Active Messaging Session w/ Default Profile[mapi] | ||
objSession.Logon ( | objSession.Logon ("YourIDHere") | ||
Do | Do | ||
'Run the CheckInbox routine, then sleep 1 minute | 'Run the CheckInbox routine, then sleep 1 minute | ||
Line 88: | Line 88: | ||
'If there are new messages, reset dteLastItemReceived, else | 'If there are new messages, reset dteLastItemReceived, else | ||
'set dteLastTimeReceived to | 'set dteLastTimeReceived to "Now" | ||
If iNewMessages > 0 Then | If iNewMessages > 0 Then | ||
dteLastItemReceived = objOneMessage.TimeReceived | dteLastItemReceived = objOneMessage.TimeReceived | ||
Line 96: | Line 96: | ||
'Report how many new messages there are | 'Report how many new messages there are | ||
MsgBox | MsgBox "There are " & iNewMessages & _ | ||
" new messages since the last time I checked." | |||
End Sub </pre> | End Sub </pre> | ||
<br /> | <br /> |
Latest revision as of 12:30, 21 July 2020
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 |