Performance problem by accessing the folder collections

O

Olivier Langlois

Hi,

I am using the following VBA function:

Function FindOrCreateFolder(inputFolder As Outlook.MAPIFolder,
folderName As String) As Outlook.MAPIFolder
Dim curFolder As Outlook.MAPIFolder
For Each curFolder In inputFolder.Folders
If folderName = curFolder.Name Then
Set FindOrCreateFolder = curFolder
Exit Function
End If
Next curFolder
Set FindOrCreateFolder = inputFolder.Folders.Add(folderName)
End Function

The reason why it is looping through all folders is that my folder
names are number ie: ('1234'). I have tried to use
inputFolder.Folders.Find(folderName) but it did not work because VBA
was interpreting the folderName parameter as an integer representing an
index. My workaround worked fine but it is becoming very slow as the
number of folders is a few thousands and still growing.

So now, I am looking for solution suggestions. Is there a way to
specify to VBA to not perform the conversion string to integer and call
the right version of Find()? Also, I have read in Sue Mosher book that
using CDO API was significantly faster than the Outlook object Model
API for accessing folder collections. This is something that I am
willing to try. Is there someone that could tell me what would look
like the CDO version of my FindOrCreateFolder() function?

Thank you very much!
Olivier Langlois
http://www.olivierlanglois.net
 
M

Michael Bauer [MVP - Outlook]

Am 11 Sep 2006 08:53:23 -0700 schrieb Olivier Langlois:

Olivier, there´s no Folders.Find function. But

On Error Resume Next
Set Folder=inputFolder.Folders("1234")
If Folder is Nothing then ... 'create it

works pretty well.
 
O

Olivier Langlois

Hi Michael,

you are right. There is no Find function. It is my mistake. I was
meaning Item() or the shortcut you used in your example. The doc says
that Item can either be the index or the name of the folder.

I have tried what you proposed but it doesn't work because if you have
a named folder "1234" and a folder named differently with the index
1234, Item() will return the folder with index 1234.

Maybe there is no way to force the Item() function to evaluate a string
composed of digits as a name and my only solution is to add a non digit
prefix to my folders.

Greetings,
Olivier Langlois
http://www.olivierlanglois.net
 
M

Michael Bauer [MVP - Outlook]

Am 12 Sep 2006 08:04:27 -0700 schrieb Olivier Langlois:

Oh, that´s interesting, I didn´t know that. But this trick helps:

set f=f.Folders(Chr(34) & "2" & Chr(34))
 
S

Sue Mosher [MVP-Outlook]

Does inputFolder.Folders.Item(folderName) work?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Michael Bauer [MVP - Outlook]

No, it doesn´t if "folderName" is a figure within the count of existing
folders. That must be a bug, OL converts the String into a Long and returns
Folders(Index) instead of Folders(Name).

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

Am Wed, 1 Nov 2006 13:55:09 -0500 schrieb Sue Mosher [MVP-Outlook]:
 
M

Michael Bauer [MVP - Outlook]

Solved in program_vba. The solution is:

set f=f.Folders(Chr(34) & "2" & Chr(34))


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

Am Wed, 1 Nov 2006 13:55:09 -0500 schrieb Sue Mosher [MVP-Outlook]:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top