How do I trap the close event for a standard email messages 
Author Message
 How do I trap the close event for a standard email messages

How do I trap the close event for a standard email messages. I have
tried both these in ThisOutlookSession code:

Function Item_Close()
  MsgBox "Testing close"
  myGlobal = False
End Function

and

Sub MyObjItem_Close(Cancel As Boolean)
    MsgBox "Testing close"
    myGlobal = False
End Sub

I need to reset a global variable when a message is cancelled i.e. not
sent how can I do this?

Thanks

Mark



Sun, 08 May 2005 04:11:26 GMT  
 How do I trap the close event for a standard email messages
Hi,
I don't know why the close event of a mailitem doesn't
work (I think because there also a Close method), but you
could try something like this.
Hope it helps.

Public WithEvents oInspectors As Inspectors
Public WithEvents oInspector As Inspector

Private Sub Application_Quit()
        Set oInspectors = Nothing
End Sub

Private Sub Application_Startup()
    Set oInspectors = Inspectors
End Sub

Private Sub oInspectors_NewInspector(ByVal oNewInspector
As Inspector)
    Set oInspector = oNewInspector
    MsgBox "New Item in Inspector"
End Sub

Private Sub oInspector_Close()
        Set oInspector = Nothing
    MsgBox "Closing Item in Inspector"
End Sub

Quote:
>-----Original Message-----
>How do I trap the close event for a standard email
messages. I have
>tried both these in ThisOutlookSession code:

>Function Item_Close()
>  MsgBox "Testing close"
>  myGlobal = False
>End Function

>and

>Sub MyObjItem_Close(Cancel As Boolean)
>    MsgBox "Testing close"
>    myGlobal = False
>End Sub

>I need to reset a global variable when a message is
cancelled i.e. not
>sent how can I do this?

>Thanks

>Mark
>.



Sun, 08 May 2005 18:59:04 GMT  
 How do I trap the close event for a standard email messages
This is actually a pretty complex subject, because you have to consider *which* message is closing .

You can use the NewInspector event to instantiate a MailItem object variable declared WithEvents. However, think about what happens if the user then opens another message: Do you switch your variable to the newly opened item?

The solution is to use a custom collection that contains items using a wrapper class. The Items Command Bar sample from the Resources section at http://www.microeye.com shows how to do this for Explorer objects. Hopefully, you can extrapolate the technique to MailItem objects.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm

Quote:

> How do I trap the close event for a standard email messages. I have
> tried both these in ThisOutlookSession code:

> Function Item_Close()
>   MsgBox "Testing close"
>   myGlobal = False
> End Function

> and

> Sub MyObjItem_Close(Cancel As Boolean)
>     MsgBox "Testing close"
>     myGlobal = False
> End Sub

> I need to reset a global variable when a message is cancelled i.e. not
> sent how can I do this?

> Thanks

> MarkT



Sun, 08 May 2005 21:22:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Trapping events in standard commandbuttons

2. Trapping of standard events

3. Trap undeliverable email message

4. Trap undeliverable email message

5. How trapping CommandBar Close Event

6. Trapping mail read, open and close events in VBA - help please

7. Can I access current email message from within email message

8. Visual Basic - Trapping Minimize/Maximize/Close Events (from the window's buttons)

9. Trapping the windows close event.

10. New Message Event Trapping

11. what event is triggered when outlook creates a new email message

12. Why does SS Tab trap key events before the form traps them

 

 
Powered by phpBB® Forum Software