none
Outlook crashes when ItemSend event executes objInspector.Close olDiscard RRS feed

  • Question

  • Within an MS Access function, I have created an Outlook MailItem object WITHOUT OUTLOOK OPEN. The Outlook Email form is displayed to the user. The function exits.

    Within Outlook's VbaProject.OTM.ThisOutlookSession.Application.ItemSend event I execute :

    Dim objInspector As Inspector

    Cancel = TRUE
    Set objInspector=Item.GetInspector
    objInspector.Close olDiscard

    On the Application.ItemSend's Exit Sub, MS Outlook crashes.
    If I open Outlook before I execute the function in MS Access, the above code works.

    How can I destroy the email item when Outlook was not opened but with an open Email Item without crashing Outlook?


    Yossi Dukes

    Thursday, April 12, 2018 7:09 PM

All replies

  • Hello YossiDukes,

    What do you want to do via the ItemSend event? Your code will prevent any mail sending, why do you need do this?

    How do you create and send mail item without opening outlook from access VBA. Did you get any error message to tell you that outlook crashed? In fact, since the outlook is not opened, I could not see whether the outlook crashed and I did not get any message that shows me that Outlook crashed. 

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 13, 2018 2:51 AM
  • Some methods cannot be called event handlers like that. Essentially, you are trying to kill an object (inspector) that is raising the very same event you are currently processing.

    A standard solution is to cancel the message submission (set the Cancel parameter to true), and start a timer. When the time fires (you will be out of the event handler by then), you can close the inspector.  


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, April 13, 2018 4:29 PM
  • @Dmitry - The workflow here is :

    a. MS Access form collects some data elements after which the user clicks a button on the form to start the process;
    b. MS Access creates an Outlook application object;
    c. MS Access creates an Outlook email item object;
    d. MS Access stores meta data from Access into a temporary file;
    e. creates a TAG property in the email item to capture the UNC file name where the meta data is stored;
    f. releases the Outlook application object referenced in MS Access;
    g. user completes the contents of the Outlook email item and clicks Send;
    h. SendItem event is trapped;
    i. SendItem opens the UNC file referenced in the TAG property of MailItem; loads the contents and information from the MailItem into an ADO Command object to execute a stored proc on a server which handles the actual sending of the email;
    j. SendItem sets the Cancel property of the MailItem to TRUE
    k. Here is where the problem occurs. *** Tryng to destroy the MailItem causes MS Outlook to crash IF MS OUTLOOK WAS NOT OPEN on step (b). If MS Outlook was already open during step (b), then destroying the MailItem at this point in the workflow works without incident. 
    I am not sure how to set a timer in Outlook when there isnt a custom form to associate the Timer to.

    Any further thoughts would be greatly appreciated.


    Yossi Dukes

    Wednesday, April 18, 2018 3:52 AM
  • Hello YossiDukes,

    >>f. releases the Outlook application object referenced in MS Access;

    Why do you release the outlook application now? I would suggest you skip this step to test if the error still occur.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 19, 2018 9:46 AM
  • Again, you are trying to kill an object that caused the event which you are currently processing.  Don't do that.

    Have you tried my suggestion?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, April 20, 2018 3:25 PM