Problem with ItemSend

A

aj

I am using VS2005 and wish to record details of an e-mail send from
my
app but I can't seem to update my form when the message is sent. I
have a simple form with one text box (txtMessage) and a button
(btnMail). Clicking btnMail fires up Outlook and when the message is
sent the ItemSend and Send events do fire but the do not allow me to
update my text box. The MsgBox do not display either but the do when
i
comment out the txtMessage lines. What am I doing wrong??? It is as
if
my form is not accessible programatically in the outlook event code.
I
am using the following code:

Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data
Imports System.Data.Common
Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Interop
Public Class frmMailTest
Dim WithEvents oApp As New Outlook.Application
Dim WithEvents oMsg As Outlook.MailItem
Private Sub btnMail_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnMail.Click
oMsg = oApp.CreateItem(OlItemType.olMailItem)
With oMsg
.To = "(e-mail address removed)"
.Subject = "Subject"
.BodyFormat = OlBodyFormat.olFormatPlain
.Body = "Type your message here"
.Display()
End With
End Sub
Private Sub oApp_ItemSend(ByVal Item As Object, ByRef Cancel As
Boolean) Handles oApp.ItemSend
txtMessage.Text = Item.body.ToString
MsgBox("Mail Sent")
End Sub
Private Sub oMsg_Send(ByRef Cancel As Boolean) Handles oMsg.Send
txtMessage.Text = oMsg.Body.ToString
MsgBox("Mail Sent")
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top