Re: Problem when Looping through large number on MS Exchange conta



It has to do with how VB Scrpt engine is releasing implicit COM objects.
Instead of using the "for each" loop, use a "for i= 1 to..." loop retrieving
each message explicitly and resetting it to Nothing inside the loop.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Carlos Lozano" <CarlosLozano@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:481D447B-7161-459A-96DA-C7F7E02CFE36@xxxxxxxxxxxxxxxx
> Hi Ken,
>
> I appreciate your help.
>
> I am using VBA for this project. Do you know How I can release resources
> using VBA?
>
> I tried setting the oObj and oContact to nothing before starting other
> cycle, but did not help.
>
> It is like the client computer is retrieving objects from the buffer or
> pipe
> faster than the server adding new ones. If the process is in break mode,
> the
> buffer is filled again and it can resume.
> Other option would be to pause the process every 100 iterations (sleep). I
> know that is possible in .NET. Do you know if it is possible in VBA?
>
> Thank you,
>
> Carlos Lozano
>
> "Ken Slovak - [MVP - Outlook]" wrote:
>
>> There is a limit of about 255 RPC channels, which in practice works out
>> usually to around 249 or 250, that you are most likely running into. The
>> problem mostly manifests itself when using the COM Interop and one of the
>> ..NET languages. If that's the case for you the only thing you can do is
>> set
>> the objects to Nothing within your loop and if that doesn't work you'd
>> have
>> to release them using Marshall.ReleaseCOMObject and maybe also explicitly
>> call the garbage collector in your loop, maybe at a 245 items count or
>> something like that.
>>
>> --
>> 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
>>
>>
>> "Carlos Lozano" <CarlosLozano@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:1E58CE93-4173-4095-9E1B-378B4F453B8C@xxxxxxxxxxxxxxxx
>> > Hi,
>> >
>> > My application loops through contact items located in a public folder.
>> > Everything works fine until the selection brings a large number of
>> > contacts
>> > (> 500).
>> > The process stops with a "type mistmatch" error when the processed item
>> > count reaches 250.
>> >
>> > I have something like this:
>> >
>> > dim oResults as Outlook.Results
>> > dim oContact as Outlook.ContactItem
>> > dim oObj as object
>> > dim i as int32
>> >
>> > ' folder AdvancedSearch, retrieving contact items in a oSearch object,
>> > ' then assigning the result to the oResults object
>> >
>> > for each oObj in oResults
>> > i = i + 1
>> > if oObj.MessageClass = "IPM.Contact" then ' To exclude distribution
>> > lists
>> > set oContact = oObj
>> > ' Additional code goes here
>> > end if
>> > next
>> >
>> > The error happens not always on same contact, but always near item 250
>> > (What
>> > a coincidence!!!)
>> >
>> > If I break the the process adding the following inside the loop:
>> > if i = 248 then
>> > debug.assert(1 = 0) 'Breaks here
>> > end if
>> >
>> > A lot of traffic happens between the client machine (Outlook) and the
>> > server
>> > MS SBS2003 machine, after that I am able to resume the process, but
>> > will
>> > eventually crash again if the processing a large enough to count
>> > another
>> > 250
>> > iterations.
>> >
>> > I will appreciate any help.
>> >
>> > Carlos Lozano
>> > CAX IT Services
>> > www.caxonline.net
>>
>>


.



Relevant Pages

  • Re: Outlook Automation Problem
    ... Dim objNS As Outlook.NameSpace ... > The error is not coming when I loop through the contacts and add each one ... > is used as the Recipient for Outlook email. ... > Not having access to a network or exchange server makes it a little ...
    (microsoft.public.vb.general.discussion)
  • Re: Outlook 2003 vba macro
    ... Sue Mosher, Outlook MVP ... > Another way of doing it is to use a for each loop ... 'Move the email Item to the backup folder ... >> Dim objApp As Application ...
    (microsoft.public.outlook.program_vba)
  • Re: looping through inbox messages / debugger under Outlook VBA
    ... Author of Microsoft Outlook 2007 Programming: ... breakpoints, view the content of variables, watch the loops loop, etc. is ... The underlying task is to read through the messages in the inbox and write ... Dim oNameSpace As Outlook.NameSpace ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Speed of reading email messages
    ... I would first of all release my objects going through the loop, not use so many dot operators assign an overall Items collection and iterate that. ... I would probably use a different API myself when iterating a large collection, for example I use Redemption to avoid the Outlook security and provide access to Stores and properties that aren't exposed in the Outlook object model. ... Dim iSelectedIndex As Integer ... Dim omelette As Object 'Outlook._Mail '= ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Problem when Looping through large number on MS Exchange contacts
    ... If that's the case for you the only thing you can do is set the objects to Nothing within your loop and if that doesn't work you'd have to release them using Marshall.ReleaseCOMObject and maybe also explicitly call the garbage collector in your loop, maybe at a 245 items count or something like that. ... dim oResults as Outlook.Results ... dim oContact as Outlook.ContactItem ... for each oObj in oResults ...
    (microsoft.public.office.developer.outlook.vba)