How to get the last received email in the inbox?

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
 
J

JP

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top