S
Sriram N A \(MICO/PJ-SAP-PP\) *
I have code in the ThisOutlookSession module which attempts to process the
current day's mail looking for a subject which begins with a number. If a
matching Distribution List is found with the same name, the item is
forwarded to the DL (There are reasons why I cannot use an auto-forward
rule).
The problem is, the Restrict method appears not be catching all instances of
"Today's mail" reliably. Is there anything wrong with this code?:
Sub SendASN()
Dim myFolder As MAPIFolder
Dim sFilter As String
Dim ItemsToProcess As Outlook.Items
Dim myItem As MailItem, myForwardItem As MailItem
Dim MyRecipient As String
'Scan through today's mail in the Inbox.
'Check whether each mail is possibly an ASN
'and forward to the appropriate contact DL
Set myFolder = Session.GetDefaultFolder(olFolderInbox)
sFilter = "[ReceivedTime] >= " & AddQuotes(Format(Date, "ddddd"))
Set ItemsToProcess =
Session.GetDefaultFolder(olFolderInbox).Items.Restrict(sFilter)
For Each myItem In ItemsToProcess
MyRecipient = Left(Replace(myItem.Subject, "FW: ", "", , 1), 6)
If IsNumeric(MyRecipient) And myItem.Attachments.Count > 0 And
CheckContact(MyRecipient) Then
Set myForwardItem = myItem.Forward
'Do my thing
End If
Next
End Sub
current day's mail looking for a subject which begins with a number. If a
matching Distribution List is found with the same name, the item is
forwarded to the DL (There are reasons why I cannot use an auto-forward
rule).
The problem is, the Restrict method appears not be catching all instances of
"Today's mail" reliably. Is there anything wrong with this code?:
Sub SendASN()
Dim myFolder As MAPIFolder
Dim sFilter As String
Dim ItemsToProcess As Outlook.Items
Dim myItem As MailItem, myForwardItem As MailItem
Dim MyRecipient As String
'Scan through today's mail in the Inbox.
'Check whether each mail is possibly an ASN
'and forward to the appropriate contact DL
Set myFolder = Session.GetDefaultFolder(olFolderInbox)
sFilter = "[ReceivedTime] >= " & AddQuotes(Format(Date, "ddddd"))
Set ItemsToProcess =
Session.GetDefaultFolder(olFolderInbox).Items.Restrict(sFilter)
For Each myItem In ItemsToProcess
MyRecipient = Left(Replace(myItem.Subject, "FW: ", "", , 1), 6)
If IsNumeric(MyRecipient) And myItem.Attachments.Count > 0 And
CheckContact(MyRecipient) Then
Set myForwardItem = myItem.Forward
'Do my thing
End If
Next
End Sub