T
Tim Baur
Hello all,
I have an odd problem, and haven't been able to determine a solution by
searching the archives. I'm hoping someone here can quickly spot what
I'm doing wrong.
I'm writing a function that searches an Exchange Inbox and returns a
collection of mail items for processing. The problem occurs when I try
to view the sender name, message body, or almost anything other than the
subject for comparison.
So far I've tried declaring my MailItem variable (oMI) as MailItem,
Variant, and Object. I've tried using
For Each oMI in ...Folders(Inbox).Items
And
For i = 1 to Folders(Inbox).Items.Count
Set oMI = Folders(Inbox).Items(i)
The oMI works fine for the first couple hundred, then simply fails when
resolving the sendername or body.
I've included a snip of my code that pertains to the search.
* * * * * * * *
Public Function GetMailItems(sSubjectMatch As String) As Collection
' Search the given MailBoxName and return all mail item objects _
where Subject LIKE sSubjectMatch
Dim colRetVal As Collection
Dim oMI As MailItem
Dim oItems As Outlook.Items
Dim lItemIdx As Long
Set colRetVal = New Collection
Set oItems = moApp.Session.Folders(msMailBoxName). _
Folders("Inbox").Items
For lItemIdx = 1 To oItems.Count
DoEvents
With oItems(lItemIdx)
If .Subject Like sSubjectMatch Then
If .Class = Outlook.OlObjectClass.olMail Then
' ######## FAILS ON NEXT LINE ########
If .SenderName = "TEST Account" Then
colRetVal.Add oItems(lItemIdx)
End If
End If
End If
End With
Next lItemIdx
Set GetMailItems = colRetVal
End Function
* * * * * * * *
Any thoughts?
Many thanks in advance.
I have an odd problem, and haven't been able to determine a solution by
searching the archives. I'm hoping someone here can quickly spot what
I'm doing wrong.
I'm writing a function that searches an Exchange Inbox and returns a
collection of mail items for processing. The problem occurs when I try
to view the sender name, message body, or almost anything other than the
subject for comparison.
So far I've tried declaring my MailItem variable (oMI) as MailItem,
Variant, and Object. I've tried using
For Each oMI in ...Folders(Inbox).Items
And
For i = 1 to Folders(Inbox).Items.Count
Set oMI = Folders(Inbox).Items(i)
The oMI works fine for the first couple hundred, then simply fails when
resolving the sendername or body.
I've included a snip of my code that pertains to the search.
* * * * * * * *
Public Function GetMailItems(sSubjectMatch As String) As Collection
' Search the given MailBoxName and return all mail item objects _
where Subject LIKE sSubjectMatch
Dim colRetVal As Collection
Dim oMI As MailItem
Dim oItems As Outlook.Items
Dim lItemIdx As Long
Set colRetVal = New Collection
Set oItems = moApp.Session.Folders(msMailBoxName). _
Folders("Inbox").Items
For lItemIdx = 1 To oItems.Count
DoEvents
With oItems(lItemIdx)
If .Subject Like sSubjectMatch Then
If .Class = Outlook.OlObjectClass.olMail Then
' ######## FAILS ON NEXT LINE ########
If .SenderName = "TEST Account" Then
colRetVal.Add oItems(lItemIdx)
End If
End If
End If
End With
Next lItemIdx
Set GetMailItems = colRetVal
End Function
* * * * * * * *
Any thoughts?
Many thanks in advance.