Outlook not processing all email items

J

Jon Mortimer

Hi, I have an issue. I have a script that is very basic in my opinion
it looks at all the emails in a certain folder, checks the Subject for
keyword and based on this files it in a specific folder. Everythin
works perfect except, out of 10 messages - for example - it onl
processes 5-7 of them. If I run the macro again, it does a few more
etc. Eventually all are processed but I don't understand what I'm doin
wrong that it doesn't cycle through all of them. I was hoping someon
could take a look at this code to see where I might be going wrong.
This code is from a much larger script but this is the important par
related to the issue.


Code
-------------------

Public appOl As New Outlook.Application
Public ns As Outlook.NameSpace
Public Inbox As Outlook.MAPIFolder
Public DestFolder As Outlook.MAPIFolder
Public Atmt As Outlook.Attachment
Public olApp As Outlook.Application
Public olNewMail As Outlook.MailItem
Public Item As Object

Private Sub Check_Support_Mailbox()
On Error GoTo Check_Support_Mailbox_err
Dim subText As String
Set ns = appOl.GetNamespace("MAPI")
Set Inbox = ns.Folders("Mailbox - MyName").Folders("Inbox")
'
For Each Item In Inbox.Items.Restrict("[UnRead] = True")
' Added this flag to see if it was looking at each msgs
' Based on this flag, it is not touching every email
Item.FlagIcon = olYellowFlagIcon
If (Item.Class = olMail) And (Item.UnRead) Then
'
' I removed the reference to all states, 3 is a good sampling
'
If InStr(Item.Subject, "AL -") 0 Then NorthIncidents
If InStr(Item.Subject, "AZ -") 0 Then WestIncidents
If InStr(Item.Subject, "AR -") 0 Then EastIncidents
End If
Next Item
Check_Support_Mailbox_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Set appOl = Nothing
Exit Sub
Check_Support_Mailbox_err:
MsgBox "Error has occurred " & Err.Number & “: “ & Err.Description, vbCritical, "Error!"
Resume Process_Report_Emails_exit
End Sub

-------------------


Also, maybe someone could offer a better solution for how I'm handlin
the keyword search? Basically, I'm looking for the STATE abbreviation i
the subject line and based on that files it appropriately. Obviously 5
IfThen statements makes no sense but I just couldn't figure a bette
way.

THANKS FOR ANY ASSISTANCE!!
 
J

Jon Mortimer

Jon said:
Hi, I have an issue. I have a script that is very basic in my opinion
it looks at all the emails in a certain folder, checks the Subject for
keyword and based on this files it in a specific folder.

I'm bumping this message in the hopes that someone will be able to hel
me on this. I'm surprised there hasn't been a response already but hop
someone has had a similar problem and might have some information on ho
to fix it, or point me in a new direction
 

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