Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / July 2007

Tip: Looking for answers? Try searching our database.

Outlook Automation Automation Problem  Out of Memory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MikeA - 24 Jul 2007 20:51 GMT
I'm not sure if I am posting to the right forum but I am having a problem
with accessing Contacts with Outlook Automation.  The program works perfect
in Outlook 2003 but gives an error on another computer with Outlook 2002.
When I try and access the .Body I get an OLE Dispatch Error Code 4096 From
Microsoft Outlook Out Of Memory.  I'm not sure if the problem is with
Outlook, the computer or perhaps I could change my programming code and how
I access the body in Outlook Contacts.

The code that gives the error is in VFP but it should be similar to VB so
here's a snapshot if it helps.  I don't think it is a coding problem but I'm
thinking perhaps there might be another way to access the body which might
not give this error.

loOutlook = createobject('outlook.application')
loNS  = loOutlook.GetNameSpace('MAPI')
loDF  = loNS.GetDefaultFolder(olFolderContacts)
loItems = loDF.items

loItem = loItems.item(1)
? loItem.Body

Also, does anyone know offhand how to access the Email field(s).

Thanks,
Mike
Ken Slovak - [MVP - Outlook] - 25 Jul 2007 14:07 GMT
If you are accessing Body in Outlook 2002 you are running into the Outlook
object model security. See http://www.outlookcode.com/article.aspx?id=52 for
an explanation and workarounds.

The email fields are also restricted and subject to the security. They are
item.EmailNAddress where N is a number from 1 to 3. If the user is on
Exchange server the email address or addresses corresponding to an Exchange
address won't have an SMTP format it will be returned in an Exchange
distinguished name format.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> I'm not sure if I am posting to the right forum but I am having a problem
> with accessing Contacts with Outlook Automation.  The program works
[quoted text clipped - 21 lines]
> Thanks,
> Mike
MikeA - 26 Jul 2007 00:32 GMT
No - I don't think it is a security issue.  I had them try and export the
calendar from my application to Outlook and it brings up the Outlook
security dialog.  I then had them enter 10 minutes so there would be plenty
of time to then try and export contacts.  It gets to around 110 of 700
contacts to export and then it errors out upon reading the body.  I don't
get it.  It reads the body for the first 100+ contacts and then errors out
and gives an "out of memory error."  But, it seems to work just fine on my
Outlook 2003 but not on their Outlook 2002.

Mike

> If you are accessing Body in Outlook 2002 you are running into the Outlook
> object model security. See http://www.outlookcode.com/article.aspx?id=52 
[quoted text clipped - 31 lines]
>> Thanks,
>> Mike
Ken Slovak - [MVP - Outlook] - 26 Jul 2007 16:07 GMT
Is this running against an Exchange server mailbox? If so it might be the
RPC channel limit. That's usually set to 255 and is set in the registry on
the server. Once you exceed that number of open RPC channels you get various
errors including out of memory errors.

If you are looping to handle multiple items then that's likely the problem.
The fixes are to eliminate usage of multiple dot operators so Outlook
doesn't open internal variables for each dot operator, explicitly releasing
your objects each pass through the loop to close their RPC channels and if
necessary using a shorter loop called repeatedly.

Normally any open internal variables aren't released until you exit the
procedure where they were created as they go out of scope. In that case your
loop procedure might have to be called repeatedly, say once for every 50 or
100 items.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> No - I don't think it is a security issue.  I had them try and export the
> calendar from my application to Outlook and it brings up the Outlook
[quoted text clipped - 6 lines]
>
> Mike
MikeA - 27 Jul 2007 04:51 GMT
Okay - I have a LOT more information now.  Here's what's going on and I do
not understand why but I have discovered that the version of Outlook is not
important at all.

I had said in my OP that it gets to around reading contact #110 and then
errors out.  What is happening is the line:

? loItem.Body

is the one erroring out.  Actually, I'm trying to read the body and it
errors out.  Now, what is interesting is for the first 110 records it works
fine but errors out on record 111.  The records are not the ones I'm trying
to import from my application but rather other records that were manually
entered in Outlook.

As it turns out, I had a similar proble on my computer.  What happend was I
ran it through a loop and when I did this on my computer it worked fine:

loItem = loItems.item(1)
? loItem.Body

But, when I did this (all from the command prompt in VFP:

loItem = loItems.item(60)
? loItem.Body

It errors out.  In fact, I can't read any properties at all for item 60.
But this line:

? loItems.count

returns 64.  So, I can't understand why for some records (that were directly
entered by me in Outlook and not imported from my database application) it
errors out but for others it works fine.  For now, my solution is to use an
ON ERROR command to trap the error and continue.  But, I am a little
perplexed as to why some objects are not returning any values.

Any thoughts?

Thanks,
Mike

> Is this running against an Exchange server mailbox? If so it might be the
> RPC channel limit. That's usually set to 255 and is set in the registry on
[quoted text clipped - 22 lines]
>>
>> Mike
Ken Slovak - [MVP - Outlook] - 27 Jul 2007 14:18 GMT
I have no idea other than maybe the items aren't of the correct type? If
that's not it then it may be corruption of some sort in the problem items.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Okay - I have a LOT more information now.  Here's what's going on and I do
> not understand why but I have discovered that the version of Outlook is
[quoted text clipped - 38 lines]
> Thanks,
> Mike
MikeA - 28 Jul 2007 07:02 GMT
If it is corruption (which is what I also suspected) is there some kind of
"pack" or "reindex" or "fix databases" command in Outlook?

Thanks,
Mike

>I have no idea other than maybe the items aren't of the correct type? If
>that's not it then it may be corruption of some sort in the problem items.
[quoted text clipped - 42 lines]
>> Thanks,
>> Mike
Ken Slovak - [MVP - Outlook] - 30 Jul 2007 14:31 GMT
Just the external applications ScanPST.exe and ScanOST.exe, both usually
located in the C:\I386 folder. You run those with Outlook closed, using the
one for whichever store type you're using.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> If it is corruption (which is what I also suspected) is there some kind of
> "pack" or "reindex" or "fix databases" command in Outlook?
>
> Thanks,
> Mike
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.