How to get the last received email in the inbox?

  • Thread starter Thread starter kf9150
  • Start date Start date
K

kf9150

Hello,

I thought the following should display the last received email in the
inbox. But apparently it is not reliable, at least from my experiment.
Any idea why?

I was thinking of sorting all the mails in inbox by the ReceivedTime
property, but that would not be fast if there are plenty emails. Any
other faster ways?

Public Sub DisplayLastReceivedMail()
Dim myNamespace As NameSpace
Dim myFolder As Folder
Dim myItem As MailItem
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set myItem = myFolder.Items(myFolder.Items.Count)
myItem.Display
End Sub

Thank you! (Btw, I'm using Outook 2007.)

Kelie
 
Doesn't the Items collection return a Folder, not an indivdual item
from that folder?

I think the GetLast method retuns the last item in a Folders
collection. Also I vaguely recall looping through a Folder with a For-
Next Loop and the first item that comes up is actually the last
received item. Or you could loop backwards through the collection.

HTH,
JP
 
Back
Top