Murray Brown
asked on
Access VBA - modify code to lokk through only new mail
Hi.
How would I modify the following code to look through only new mail items
Dim Olook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim OMail As Outlook.MailItem
Dim LookFor As String
Set Olook = New Outlook.Application
Set oNs = Olook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFol derInbox)
LookFor = "a"
Me.ListBox.RowSource = ""
For Each OMail In oFldr.Items
With OMail
If InStr(.Subject, LookFor) Then
Me.List1.AddItem (OMail.Subject)
End If
End With
Next OMail
Set OMail = Nothing
Set oFldr = Nothing
Set oNs = Nothing
Set Olook = Nothing
How would I modify the following code to look through only new mail items
Dim Olook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim OMail As Outlook.MailItem
Dim LookFor As String
Set Olook = New Outlook.Application
Set oNs = Olook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFol
LookFor = "a"
Me.ListBox.RowSource = ""
For Each OMail In oFldr.Items
With OMail
If InStr(.Subject, LookFor) Then
Me.List1.AddItem (OMail.Subject)
End If
End With
Next OMail
Set OMail = Nothing
Set oFldr = Nothing
Set oNs = Nothing
Set Olook = Nothing
A better approach might be to use the Application_NewMail event of Outlook. This event (located in the ThisOutlookSession class module) fires when a new mail message arrives.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much
Thank you Helen_Feddema: for your input but already did that - this is additional code to manually run things to capture data that wasn't handled by that event
Thank you Helen_Feddema: for your input but already did that - this is additional code to manually run things to capture data that wasn't handled by that event