folder.Items.count doesnt work with Outlook2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Show the code you're using. All of my code that iterates folders still works
identically in Outlook 2003 and even Outlook 2007.
 
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
 
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?
 
Back
Top