Code Returning Half of the Values

P

PJFry

I am running code that exports data releated to unread messages in an inbox.
What is puzzling me is that the code only returns half of the values that it
is supposed to. For example, if I have 50 unread messages, it will export
the data on the first 25 and stop. Any ideas what is causing this?

I am running OL 2003 on Windows XP Pro.

Sub SupplierSurvey()

With Application.Session

ExportMessageDetails .Folders("Mailbox - Quality
Department").Folders("Inbox")
End With
End Sub


Function ExportMessageDetails(vFolder As MAPIFolder) As Boolean
On Error GoTo Err_Handler
Kill "H:\SupplierSurvey.txt"

Dim vItem As Object, vFF As Long, vFile As String
vFF = FreeFile
vFile = "H:\SupplierSurvey.txt"
For Each vItem In vFolder.Items
If TypeName(vItem) = "MailItem" Then
If vItem.UnRead Then
Open vFile For Append As #vFF
Print #vFF, vFolder.Name & vbTab &
Format(vItem.ReceivedTime, "mm/dd/yyyy hh:mm:ss")

Close #vFF
End If

End If
Next

Err_Handler:
Resume Next

End Function

Thanks!

PJ
 
E

Eric Legault [MVP - Outlook]

Strange. See what happens if you temporarily move 30 of those messages to
another folder and run your code again.

Also, remove the error handling so if any errors do occurr you'll know right
away.
 
P

PJFry

Figures it out. What I was trying to do was count the number of unread
items, specifically Undeliverable mail. In this case, exactly half of the
messages were undeliverable. The code is supposed to look at MailItems,
which I am guessing undeliverable mail is not. Once I cleared those message
out, I got the result I was expecting.

So that begs the question, what kind of an item is undeliverable mail?
 
K

Ken Slovak - [MVP - Outlook]

If it passes the MailItem test it will be some variation of *.IPM.Note.*.
You can set the folder to a bottom reading pane view and customize the view
to see the exact MessageClass. Depending on the server and the source of the
message it could really be anything.

An undeliverable message that I get from my Exchange server has a
MessageClass of "REPORT.IPM.Note.NDR"
 

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