October 24, 2016
Hot Topics:

Making Microsoft Outlook Useful - Part 2

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

Right, lets get our heads down to some serious code! Reading through messages in a given folder was introduced to you in the previous article, so you should be up to speed on that. Now the first thing Im going to show you is an easy way to get only the latest messages, within a few days of the current date:

(For this code you need a list box called lstNewMessages and a text box called txtDate with a .text value of something like 01/01/01)

Private Sub Form_Load()  Dim objOutlook As New Outlook.Application  Dim objNameSpace As Outlook.NameSpace  Dim objFolder As MAPIFolder  Dim objMail As MailItem      ' Get the MAPI name space  Set objNameSpace = objOutlook.GetNamespace("MAPI")    ' Get a ref to the folder we want  Set objFolder = objNameSpace.GetDefaultFolder(olFolderInbox)    ' Read through all the items  For i = 1 To objFolder.Items.Count    Set objMail = objFolder.Items(i)        ' Check the sent date for validity    If objMail.SentOn >= CDate(txtDate.Text) Then      ' Add it to the list box      lstNewMessages.AddItem objMail.Subject      lstNewMessages.ItemData(lstNewMessages.NewIndex) = i    End If  Next iEnd Sub

OK. This is a pretty basic start. Lets move on to something a bit more demanding...

Page 3 of 4

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel