views:

50

answers:

2

We currently use the following code to create an email in Outlook so that the user can type what they want in Outlook, then when the email is sent, the system prompts them to see if they would like to save the email.

            Dim objOutlook As Object
            Dim objMessage As Object
            Dim objInspector As Object

            If strEMail <> "" Then
                objOutlook = CreateObject("Outlook.Application")
                objMessage = objOutlook.CreateItem(0)
                objMessage.To = strEMail

                objInspector = objMessage.GetInspector
                objInspector.Display()

                While Not objInspector.CurrentItem Is Nothing
                End While

                frmSaveSentEmail.BringToFront()
                frmSaveSentEmail.ShowDialog()

The code works fine on Outlook 2003 as long as they are not using Word as their email editor. However, with Word set up as the email editor, the while loop that tests to see if the email object is closed never ends.

Is there a way to handle this differently so that it will work even with Word as the editor?

A: 

I am not terribly experienced with programming Outlook via VB.NET, but that loop certainly looks suspicious. Perhaps you should try taking advantage of the inspector's Close event instead of repeatedly checking its CurrentItem property. If I am not mistaken, you should be able to present your dialog within the event handler.

Adam Paynter
A: 

Ended up changing the loop to:

  While Not objOutlook.ActiveInspector Is Nothing
  End While

This resolved the issue.

KevenDenen