A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

MailItem.Close()



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 18th 09, 03:22 PM posted to microsoft.public.outlook.program_vba
Bina
external usenet poster
 
Posts: 4
Default MailItem.Close()

Is MailItem.Close() a synchronous or asynchronous operation? In other words,
if I first close my MailItem and then call Delete() on it, should this work?

Bina

  #2  
Old February 18th 09, 04:29 PM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default MailItem.Close()

Calling Close on your MailItem closes the item, but does not destroy your
reference to it. You can therefore call Delete thereafter.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Bina" wrote:

Is MailItem.Close() a synchronous or asynchronous operation? In other words,
if I first close my MailItem and then call Delete() on it, should this work?

Bina

  #3  
Old February 18th 09, 04:38 PM posted to microsoft.public.outlook.program_vba
Bina
external usenet poster
 
Posts: 4
Default MailItem.Close()

I am concerned about whether the call to Close() is a synchronous or
asynchronous operation. If I am displaying an email, and I call the Close()
function, and it is asynchronous, I may be trying to Delete the item while it
is still being displayed.

The background for my question is that I have created a temporary folder
with an email in order to display it. I want to Close() the email and delete
the folder and the email. However, sometimes (not in all cases) the delete
operation fails with a permissions error. If I wait a while and then delete,
or step through this process in a debugger, it never fails. So, I was
wondering if Close() is actually an asynchronous operation. If so, is there
a way to know when it has completed?

"Alan Moseley" wrote:

Calling Close on your MailItem closes the item, but does not destroy your
reference to it. You can therefore call Delete thereafter.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Bina" wrote:

Is MailItem.Close() a synchronous or asynchronous operation? In other words,
if I first close my MailItem and then call Delete() on it, should this work?

Bina

  #4  
Old February 18th 09, 04:56 PM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default MailItem.Close()

I do not know for certain if it is synchronous or not, but I suspect that it
is. Can you post the relevant section of your code. I suspect that you are
under certain circumstances not setting the mailitem's object variable back
to nothing before deleting the folder. Also, calling the mailitem's delete
method invokes the inspector to close anyway, so you probably do not need to
call it separately.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Bina" wrote:

I am concerned about whether the call to Close() is a synchronous or
asynchronous operation. If I am displaying an email, and I call the Close()
function, and it is asynchronous, I may be trying to Delete the item while it
is still being displayed.

The background for my question is that I have created a temporary folder
with an email in order to display it. I want to Close() the email and delete
the folder and the email. However, sometimes (not in all cases) the delete
operation fails with a permissions error. If I wait a while and then delete,
or step through this process in a debugger, it never fails. So, I was
wondering if Close() is actually an asynchronous operation. If so, is there
a way to know when it has completed?

"Alan Moseley" wrote:

Calling Close on your MailItem closes the item, but does not destroy your
reference to it. You can therefore call Delete thereafter.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Bina" wrote:

Is MailItem.Close() a synchronous or asynchronous operation? In other words,
if I first close my MailItem and then call Delete() on it, should this work?

Bina

  #5  
Old February 18th 09, 07:07 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default MailItem.Close()

Close is synchronous but you can't delete the item in that event handler
without errors in some versions of Outlook.

Outlook also caches items so you have to wait for it to be released.

I usually use a timer to do the deletions and set up an array of EntryID's
of items to delete. When the timer fires I sweep the array clean.

--
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


"Alan Moseley" wrote in message
...
I do not know for certain if it is synchronous or not, but I suspect that
it
is. Can you post the relevant section of your code. I suspect that you
are
under certain circumstances not setting the mailitem's object variable
back
to nothing before deleting the folder. Also, calling the mailitem's
delete
method invokes the inspector to close anyway, so you probably do not need
to
call it separately.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


  #6  
Old March 17th 09, 06:07 PM posted to microsoft.public.outlook.program_vba
SteFetS
external usenet poster
 
Posts: 1
Default MailItem.Close()

Hello,

What we have done at work is to create a thread

In the Inspector Clos event :

If RemoveItemAfterClose Then
Dim TS As New System.Threading.ThreadStart(AddressOf
WrapperMailItem.Delete)
Dim t As System.Threading.Thread = New System.Threading.Thread(TS)
Try
t.Start()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If

Works like a charm


"Ken Slovak - [MVP - Outlook]" wrote:

Close is synchronous but you can't delete the item in that event handler
without errors in some versions of Outlook.

Outlook also caches items so you have to wait for it to be released.

I usually use a timer to do the deletions and set up an array of EntryID's
of items to delete. When the timer fires I sweep the array clean.

--
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


"Alan Moseley" wrote in message
...
I do not know for certain if it is synchronous or not, but I suspect that
it
is. Can you post the relevant section of your code. I suspect that you
are
under certain circumstances not setting the mailitem's object variable
back
to nothing before deleting the folder. Also, calling the mailitem's
delete
method invokes the inspector to close anyway, so you probably do not need
to
call it separately.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Close a Excel Workbook when close a userform in Outlook [email protected] Outlook and VBA 2 May 8th 08 02:54 PM
MailItem Close Event Robert Morley Outlook and VBA 8 April 19th 07 09:03 PM
Close Message, Close Outlook cdf Outlook - General Queries 2 April 16th 07 03:42 PM
How to Add a MailItem to a Folder Ron Outlook and VBA 2 January 10th 07 08:53 PM
How can I create a MailItem that displays like a received MailItem ? Clive Outlook - Using Forms 0 February 27th 06 04:14 PM


All times are GMT +1. The time now is 02:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.