VBA-run-through stopping after abount 250 items

G

Guest

I need to run through all items (about 5000) in a public folder once in a
while. Lately I have upgraded to XP Pro and I think that might have caused
some problems.

The error I get every time the computer has read about 250 items is
"Run time error 13: Type mismatch"

When debugging and placing the cursor right on top of ".Item(intCounter)" I
can see how far the computer got in the code. Next time I can start over at
item no 249 and then I get the error around item no 500.

The code I use starts this way:

"For intCounter = 1 To objContacts.Count
Set objContact = objContacts.Item(intCounter)
With objContact
....
"

Maybe it's a memory management thing but I would like to go through all
items without stopping every 250 items. Any ideas why this happens and if it
can be cured??

I have tried to run the code on different XP Pro computers. One with 512 Mb
Ram and one with 1 Gb Ram. Same problems.

When running 2000 Pro I didn't have this problem. And I don't think I have
changed my code since then.


Regards

- Allan


(Running Exchange Server 2003 with Outlook 2003 clients)
 
G

Guest

This is actually an Exchange issue:

Your Exchange Server 2003 computer may stop responding after a MAPI client
opens more than the default value of certain server objects:
http://support.microsoft.com/kb/830829/

Also, ensure that your code doesn't expect a certain type of object when
looping through items in a folder. Inspect the Item types in the collection
you are retrieving them from (like the Class or MessageClass properties, or
use TypeOf(Object)) before you assign them to an explict object type. For
example, when looping through items in a Contact folder, some items may be
Distribution Lists and they cannot be assigned to a Contact object.
 
G

Guest

Thank you, Eric for answaring.

I will try to modify my code. Right now I don't quite know what to modify
but I will look into it.

Unfortunately the Microsoft-link is not available.

If my problem is related to Exchange why didn't I realise the problem when
running 2K Pro on my client?
 
G

Guest

You're right, it may not be Exchange related. There is another issue related
to this that seems specific to Outlook 2002, but I'm not sure if this is
relevant to Outlook 2003 or not:

OL2002: Memory or Performance Problems Looping Through Items:
http://support.microsoft.com/?kbid=293797

BTW, Microsoft's Knowledge Base seems to be having some problems this week,
so keep trying to access those articles.

Change this part of your code to handle different item types:

For intCounter = 1 To objContacts.Count
If objContacts.Item(intCounter).Class = olContact Then
Set objContact = objContacts.Item(intCounter)
'...code to work with a Contact item
Else
'...code to handle non-Contact items
End If

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 
G

Guest

I will access the KB-articles later.

If I know that every item in the folder are olContacts would the code
modification you suggest then make any difference at all?
 
G

Guest

I will consider your suggestions when programming VBA in the future.

Seems that the KB-article is solving my problem:
OL2002: Memory or Performance Problems Looping Through Items:
http://support.microsoft.com/?kbid=293797

Now I can loop through my entire folder. Although the garbage collection
after completion of the code is very slow. But I can somehow live with that.

Great support. Thank you very much, Eric.
 

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