Close item

Status
Not open for further replies.
R

Richard Elgert

I am trying to open/read all email in the inbox.. (trying to delete duplicates)

Get error at 250th item sayin the system settings do not allow any more open than that

have this in code

' need to close the email

oMsg.Close(OlInspectorClose.olSave)

but does not close the mail item

how do I close properly so no error
 
K

Ken Slovak - [MVP - Outlook]

Managed code with Exchange mailbox? That's the RPC channel limit, unless the

object reference is released that error will result after about 250 or so

operations.

Set the object to null each pass through the code, if necessary also call

Marshal.ReleaseComObject() on it and GC.Collect(). That will release all

those RPC channels that otherwise wouldn't be released until the procedure

ended and the objects went out of scope.

Also don't use concatenated dot operators:

string body = olApp.ActiveInspector.CurrentItem.Body;

Set up a variable for each dot operator so you can explicitly release

things. Otherwise intrinsic variables are created internally and you cannot

release those:

Outlook.Inspector insp = olApp.ActiveInspector;

Outlook.MailItem item = (Outlook.MailItem)insp.CurrentItem;

string body = item.Body;

"Richard Elgert" <relgert[at]tct-inc[dot]com> wrote in message

news:OarzC9o7JHA.4632@TK2MSFTNGP02.phx.gbl...
> I am trying to open/read all email in the inbox.. (trying to delete
> duplicates)

> Get error at 250th item sayin the system settings do not allow any more
> open than that

> have this in code
> ' need to close the email
> oMsg.Close(OlInspectorClose.olSave)

> but does not close the mail item

> how do I close properly so no error

>
 
R

Richard Elgert

retValue = System.Runtime.InteropServices.Marshal.ReleaseComObject(oMsg )

GC.Collect()

OK I did add the above 2 lines and the 250 limit error is gone.... but I am not sure I fully understand... (will your book clarify)

and a follow up, I need to browse all folders and sub-folders in a users mailbox. .
 
K

Ken Slovak - [MVP - Outlook]

My book might mention the RPC limit but it's strictly an Exchange setting

that's controlled by a registry setting on the server. It limits how many

RPC channels any application can open at any one time so as not to bog down

the server. Since the setting can be anything if the admins change the

default, all you really need to understand is to follow best practices and

release your objects as soon as they are not needed and not to create

intrinsic object variables by using compound dot operators, especially

within loops where the objects will persist until the procedure running the

loop has ended.

I don't understand your question about folder browsing. Just use a recursive

procedure that digs into each MAPIFolder.Folders collection, starting with

the NameSpace.Folders collection or at a selected starting point.

"Richard Elgert" <relgert[at]tct-inc[dot]com> wrote in message

news:Ob4mT6y7JHA.4100@TK2MSFTNGP06.phx.gbl...
> retValue = System.Runtime.InteropServices.Marshal.ReleaseComObject(oMsg )
> GC.Collect()

> OK I did add the above 2 lines and the 250 limit error is gone.... but I
> am not sure I fully understand... (will your book clarify)

> and a follow up, I need to browse all folders and sub-folders in a users
> mailbox. .
 
R

Richard Elgert

Well to make a long story short... the whole purpose of this exercise was to delete duplicate emails... from several import of lotus Notes int Outlook, we wound up with hundreds of dupes. Tried the 'ODIR' recommended program, but that did not delete them... my code test showed that they all had a unique record ID.

Bought "Duplicate Email Remover" for $30 dollars and that did the job just fine...

I will work on my code when time permits....
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
D help with Item/Inspector close event Outlook VBA and Custom Forms 1
O Outlook 365 - Toolbar - Close all items - missing? Using Outlook 3
K Working with Explorer.Close event Outlook VBA and Custom Forms 3
Diane Poremsky How to Compact the Data File When you Close Outlook Using Outlook 0
Diane Poremsky Close a Meeting When the Room is Full Using Outlook 0
L Gmail POP, Android IMAP, Outlook 2013 setup close Using Outlook 5
D Close Oulook after sending emails via vba without outbox getting stuck. Outlook VBA and Custom Forms 1
D RUN SCRIPT WHEN OUTLOOK IS CLOSE Outlook VBA and Custom Forms 1
F Automatically close email after selecting mark unread Using Outlook 1
S Pop up reminder while i close outlook Outlook VBA and Custom Forms 5
Y (Shared Folder) Using the preview pane to open and close a fax, without opening the email itself Using Outlook 1
C Open/Close Outlook - Via Excel VBA Using Outlook 2
J OL wont close after VB app runs Using Outlook 17
Q Looking for Outlook 2010 Close Event Id Exchange Server Administration 1
R Can't close Personal Folders after switching to Exchange 2010 Using Outlook 2
R Outlook and google calendar stuck if I close outlook Using Outlook 1
J Messages close themselves - Outlook 2007 Using Outlook 1
P Minimize button causes Outlook to close 2007 Using Outlook 1
D Cannot Close pst file Using Outlook 1
K The file c:\...\Outlook1.pst cannot be accessed because another workstation has modified it. Close a Using Outlook 2
R Outlook 2003 - Close parent form before opening child form Outlook VBA and Custom Forms 4
S Error 287 on Inspector.Close() Outlook VBA and Custom Forms 4
D Macro to Close Open Messages Outlook VBA and Custom Forms 3
E How to know if a Form.Close Event is the result of canceling Outlook VBA and Custom Forms 3
Q Why is BCM causing Outlook to close? BCM (Business Contact Manager) 2
V Move email using the Close event Outlook VBA and Custom Forms 11
U Re: MailItem.Close() Outlook VBA and Custom Forms 1
H Outlook Does Not Really Close When I Close It BCM (Business Contact Manager) 1
O In Agenda-view - How to copy an existing item months ahead or back? Using Outlook 0
S Outlook 2016 dont delete inbox item Using Outlook 0
talla Can't open Outlook Item. Using Outlook 0
N Item cannot be saved because it was modified by another user or window, and, Item could not be moved... Using Outlook 0
B Zoom automatically next email item (VBA) Outlook VBA and Custom Forms 2
S Command Button_Click action on Item/Reminder Outlook VBA and Custom Forms 3
A Unflag Inbox and Flag Inbox with Orange Category After Item is send Outlook VBA and Custom Forms 3
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
C Copy Move item won't work Outlook VBA and Custom Forms 2
T Pictures degrade each time an Outlook item is edited and re-saved Using Outlook 1
B Change row background color of selected item Using Outlook 1
P Outlook 2013 "Item could not be moved - still an issue for Outlook 2013 Using Outlook 0
R Error when trying to forward current email item Outlook VBA and Custom Forms 7
geoffnoakes Find Contacts with UDFs "in this item" Using Outlook 1
T "cannot find the calendar folder for this item" - calendar items stuck in outbox Using Outlook 0
GregS Many Sent Item folders Using Outlook 3
B Select / activate first email item in the searched query Using Outlook 1
4 Macro to set the category of Deleted Item? Outlook VBA and Custom Forms 2
N "Discussion" item Using Outlook 3
T outlook.com opens with "item not found" Using Outlook 1
Peter H Williams How to Move Mail item after processing Outlook VBA and Custom Forms 5
C Change default "Save Sent Item To" folder Outlook VBA and Custom Forms 9

Similar threads

Top