Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / April 2007

Tip: Looking for answers? Try searching our database.

folder.Items.count doesnt work with Outlook2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RSunday - 26 Apr 2007 11:36 GMT
I have some VBA code in Access that reads mails. It works in Outlook 2000 -
but now with Outlook 2003 it doesn't any more.

I loop through the contents of a mail folder based on the value
"folder.Items.count" where "folder" is an Outlook.MAPIFolder - but now it
shows count = 0

Is there something I should change in my objects or what...

Alternatively some sample code showing how to get the mail objects from a
folder would be relevant.

Thanks
Ken Slovak - [MVP - Outlook] - 26 Apr 2007 15:00 GMT
Show the code you're using. All of my code that iterates folders still works
identically in Outlook 2003 and even Outlook 2007.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

>I have some VBA code in Access that reads mails. It works in Outlook 2000 -
> but now with Outlook 2003 it doesn't any more.
[quoted text clipped - 9 lines]
>
> Thanks
RSunday - 27 Apr 2007 11:14 GMT
This is my code:

Public Sub fill_mail_table(folder As Outlook.MAPIFolder, no As Integer)
   Dim mail As Savemaildata
   Dim dbs As Database
   Dim rst As Recordset
   Dim to_list As String
   Dim i As Integer
   
   Set dbs = CurrentDb
   Set rst = dbs.OpenRecordset("folder mails")
   
   ' get all mails in the folder
   mail = Get_first_Mail(folder)
   Do While Not OutlookEOF()
       With rst
           .AddNew
           ![mail index] = glngCurrentItem
           !MessageID = mail.MessageID
           !Subject = mail.Subject
           !body = mail.body
           !from = mail.from
           !received = mail.received
           !created = mail.CreateDate
           !folder = no
           to_list = ""
           i = 0
           While i < UBound(mail.Recipients)
               i = i + 1
               to_list = to_list & mail.Recipients(i) & ";"
           Wend
           !to = left(to_list, 255)
           .update
       End With
       mail = Get_next_Mail(folder)
   Loop
           
End Sub

the following procedures are called - and in the Get_first_Mail, the code
stops as
folder.Items.count shows 0.

Public Function Get_first_Mail(folder As Outlook.MAPIFolder) As Savemaildata
   Dim tMailItem As Savemaildata
   'Dim objitem As Outlook.MailItem 'changed 2001-03-29
   Dim objitem As Object
   
   glngCurrentItem = 0
   glngMaxItems = 0
   
   glngMaxItems = folder.Items.count
   If glngMaxItems > 0 Then
       glngCurrentItem = 1
       Set objitem = folder.Items.Item(glngCurrentItem)
       tMailItem = OutlookParseItem(objitem, gstrSaveFolder)
       Get_first_Mail = tMailItem
   End If
End Function

Public Function Get_next_Mail(folder As Outlook.MAPIFolder) As ABCmaildata
   Dim tMailItem As Savemaildata
   'Dim objitem As Outlook.MailItem 'changed 2001-03-29
   Dim objitem As Object

   glngCurrentItem = glngCurrentItem + 1

   If Not OutlookEOF Then
       Set objitem = folder.Items.Item(glngCurrentItem)
       tMailItem = OutlookParseItem(objitem, gstrSaveFolder)
       Get_next_Mail = tMailItem
   End If
End Function

> Show the code you're using. All of my code that iterates folders still works
> identically in Outlook 2003 and even Outlook 2007.
[quoted text clipped - 12 lines]
> >
> > Thanks
Ken Slovak - [MVP - Outlook] - 27 Apr 2007 14:48 GMT
The code looks OK to me offhand. Have you stepped it and made sure that the
folder that's passed is the correct one and made sure everything else is OK
up to folder.items.count returning 0?

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> This is my code:
>
[quoted text clipped - 70 lines]
>    End If
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.