View Single Post
  #3  
Old January 18th 07, 11:11 AM posted to microsoft.public.outlook.program_vba
Simon Maystre
external usenet poster
 
Posts: 2
Default Slow retrieving items from Outlook


This did the trick to speed up the load by around 500%! I also changed how I
was referencing the item object slightly and this also improved load time:

Thanks for your help.

Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(M ailBox)
Set objOutlookItems = objFolder.Items

With objOutlookItems

.SetColumns ("From, To, SenderName, Subject, SentOn")
lngCount = .Count

If lngCount 0 Then

ReDim aryEmails(3, lngCount - 1)

For lngCount2 = 1 To lngCount

aryEmails(0, lngCount2 - 1) = lngCount2

If MailBox = 5 Then
aryEmails(1, lngCount2 - 1) = Nz(.Item(lngCount2).To, "")
Else
aryEmails(1, lngCount2 - 1) =
Nz(.Item(lngCount2).SenderName, "")
End If

aryEmails(2, lngCount2 - 1) = Nz(.Item(lngCount2).Subject, "")
aryEmails(3, lngCount2 - 1) = .Item(lngCount2).SentOn
Progress lngCount2

Next

End If

End With





"Sue Mosher [MVP-Outlook]" wrote:

Try using the SetColumns method to retrieve only those properties that you're interested in, e.g.:

.Item.SetColumns ("To, Subject, SentOn")

--
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

"Simon Maystre" wrote in message ...

I am accessing Outlook from Access VBA and whilst the following code works
just fine it seems really slow to just show a list of the mail items that are
in the Inbox are there any suggestions on how this could be speeded up.

Set objFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(M ailBox)

With objFolder

lngCount = .Items.Count

If lngCount 0 Then

For Each objOutlookMail In .Items

aryEmails(1, lngCount2) = Nz(objOutlookMail.To, "")
aryEmails(2, lngCount2) = Nz(objOutlookMail.Subject, "")
aryEmails(3, lngCount2) = objOutlookMail.Senton

lngCount2 = lngCount2 + 1

Next

End If

End With

Many thanks



Ads