How NOT to count notifications?

  • Thread starter Thread starter Martin Los
  • Start date Start date
M

Martin Los

I have a macro counting the number of emails in Outlook
2002 depending on the day it arrived. However, if there is
a notification in the mailbox, the macro doesn´t work.
MACRO
**********************
Set objMAPIInboxFolder = objNameSpace.Folders
(MailBox).Folders("Inbox")
Set objMailItem = objApp.CreateItem(olMailItem)

For Each objMailItem In objMAPIInboxFolder.Items
If Format(objMailItem.ReceivedTime, "dd/mm/yyyy") = Format
(dateCalcDate, "dd/mm/yyyy") Then Counter = Counter + 1
Next objMailItem

.....
***************************
The problem is that a notification is not a objMailItem.

Any idea how to solve this problem?
 
Hello-

If I understand your question, you have notifications in
your mailbox that you don't want to include in the count.

Have you tried something like this?:

For Each objMailItem In objMAPIInboxFolder.Items
If .Class = olMailItem Then
' Now check the date format etc.

HTH,

-Andrew
=====================================
 
Don't Dim objMailItem as MailItem. Dim it as Object and check its Class
property to determine what type of item it is before you invoke
MailItem-specific properties and methods.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I have a macro counting the number of emails in Outlook
2002 depending on the day it arrived. However, if there is
a notification in the mailbox, the macro doesn´t work.
MACRO
**********************
Set objMAPIInboxFolder = objNameSpace.Folders
(MailBox).Folders("Inbox")
Set objMailItem = objApp.CreateItem(olMailItem)

For Each objMailItem In objMAPIInboxFolder.Items
If Format(objMailItem.ReceivedTime, "dd/mm/yyyy") = Format
(dateCalcDate, "dd/mm/yyyy") Then Counter = Counter + 1
Next objMailItem

.....
***************************
The problem is that a notification is not a objMailItem.

Any idea how to solve this problem?
 
Dear Sue and Andrew:

Thanks for both your contributions that have helped me
along the way!

Yours sincerely

Martin Los
 
Since I am relatively new to Outlook VBA, I try some code
that should combine both advices of Sue and Andrew. Is
this what should work (I have some doubts how to dim
objMailItem as an Object). Is Dim as Item what you mean
Sue?

Dim objMailItem As Item

Set objMAPIInboxFolder = objNameSpace.Folders
(MailBox).Folders("Inbox")
Set objMailItem = objApp.CreateItem(olMailItem)

For Each objMailItem In objMAPIInboxFolder.Items
If .Class = olMailTem Then

If Format(objMailItem.ReceivedTime, "dd/mm/yyyy") = Format
(dateCalcDate, "dd/mm/yyyy") Then Counter = Counter + 1
Next objMailItem

End If
End If

TIA

Martin
 
No, as Object:

Dim objMailItem as Object

Other comments inline.

You might also want to take a look at the information at
http://www.outlookcode.com/d/finddate.htm on using the Find and Restrict
methods to work with items that fit your date criteria. That would be much
more efficient that checking the date on every item in the Inbox.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Since I am relatively new to Outlook VBA, I try some code
that should combine both advices of Sue and Andrew. Is
this what should work (I have some doubts how to dim
objMailItem as an Object). Is Dim as Item what you mean
Sue?

Dim objMailItem As Item

Set objMAPIInboxFolder = objNameSpace.Folders
(MailBox).Folders("Inbox")
If this is your default Inbox, you can use the Namespace.GetDefaultFolder
method instead.

Set objMailItem = objApp.CreateItem(olMailItem)

For Each objMailItem In objMAPIInboxFolder.Items
You don't need to set objMailItem to a new item if you're immediately
going to use the same objMailItem object to loop through your Inbox.

If .Class = olMailTem Then
Check the object browser and Help for allowable values for the Class
property. You want olMail, not olMailTem [sic].

If Format(objMailItem.ReceivedTime, "dd/mm/yyyy") = Format
(dateCalcDate, "dd/mm/yyyy") Then Counter = Counter + 1


Next objMailItem
Just Next, not Next objMailItem.

End If
End If
 
That was just what I needed :)

Thanks a million Sue!

Martin
-----Original Message-----
No, as Object:

Dim objMailItem as Object

Other comments inline.

You might also want to take a look at the information at
http://www.outlookcode.com/d/finddate.htm on using the Find and Restrict
methods to work with items that fit your date criteria. That would be much
more efficient that checking the date on every item in the Inbox.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Since I am relatively new to Outlook VBA, I try some code
that should combine both advices of Sue and Andrew. Is
this what should work (I have some doubts how to dim
objMailItem as an Object). Is Dim as Item what you mean
Sue?

Dim objMailItem As Item

Set objMAPIInboxFolder = objNameSpace.Folders
(MailBox).Folders("Inbox")
If this is your default Inbox, you can use the
Namespace.GetDefaultFolder
method instead.

Set objMailItem = objApp.CreateItem(olMailItem)

For Each objMailItem In objMAPIInboxFolder.Items
You don't need to set objMailItem to a new item if
you're immediately
going to use the same objMailItem object to loop through your Inbox.

If .Class = olMailTem Then
Check the object browser and Help for allowable values
for the Class
property. You want olMail, not olMailTem [sic].

If Format(objMailItem.ReceivedTime, "dd/mm/yyyy") = Format
(dateCalcDate, "dd/mm/yyyy") Then Counter = Counter + 1


Next objMailItem
Just Next, not Next objMailItem.

End If
End If



.
 
Back
Top