A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Error when cycling through inbox items with VB programs.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 7th 06, 02:49 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Error when cycling through inbox items with VB programs.

Not every item in your Inbox is necessarily a MailItem. Declare MyMail as Object and throw in an On Error Resume Next statement.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Greg" wrote in message ...
I am working on a program to get the attachments from items in my
inbox. I know that there are 501 items in my inbox.

However, after looking at the 316th item, I get a type mismatch at the
"Next MyMail" line.

Can anyone shed any light on this? Here is my code to recreate the
error.

Is there any other type of item other than a MailItem that is in the
501 count that could be causing the problem?

Private Sub GetAttachments()
Dim OL As Outlook.Application
Dim OLNS As Outlook.NameSpace
Dim InBox As Outlook.MAPIFolder
Dim MyMail As MailItem
Dim MyAttachment As Attachment
Dim numAttachments As Integer
Dim numItems As Integer

Set OL = New Outlook.Application
Set OLNS = OL.GetNamespace("MAPI")
Set InBox = OLNS.GetDefaultFolder(olFolderInbox)

numItems = 0
numAttachments = 1
MsgBox InBox.Items.Count & " items in inbox"

For Each MyMail In InBox.Items
numItems = numItems + 1
txtData.Text = txtData.Text & vbCrLf & numItems
txtData.SelStart = Len(txtData.Text)

Next MyMail

Set OL = Nothing
Set OLNS = Nothing
Set InBox = Nothing
Set MyMail = Nothing
Set MyAttachment = Nothing

' Unload Me
End Sub

Thanks.

Greg

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I keep items in the inbox when rule is applied cscoby Outlook - Installation 1 October 25th 06 09:53 PM
Merge Inbox and Sent Items into one folder? Will Richards Outlook - Installation 1 August 17th 06 05:06 PM
Outlook: inbox and sent items in one folder vamail Outlook - General Queries 1 April 4th 06 05:10 AM
No. of Items in Inbox Steve T Outlook - General Queries 3 March 9th 06 09:23 PM
Inbox, Sent Items & Outbox in Deleted Items in Outlook 2003 & OWA with Exchange splounx Outlook - General Queries 1 February 17th 06 02:22 AM


All times are GMT +1. The time now is 03:38 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.