application item send

S

sophie

hi,
I want to code a small project which can pop up a warning when user click
send a email.
But it doesnt work for application_itemsend.
i work with VS2008, vb.

the code is here.

Public Class ThisAddIn
Public WithEvents myOlApp As Outlook.Application
Event ItemSend As AssemblyLoadEventHandler


Public Sub Initialize_handler()
myOlApp = CreateObject("Outlook.Application")
End Sub


Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
Initialize_handler()
End Sub

Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shutdown

End Sub

Private Sub myOlAppEvents_ItemSend(ByVal Item As Object, ByVal Cancel As
Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If

End Sub

End Class

Any help is appreciated.
 
S

sophie

i cannot capture itemsend event. I can capture the event in visual Basic 6.0
in the same way. but i cant get it here in vb studio 2008. I dont know why.
 
K

Ken Slovak - [MVP - Outlook]

In a VSTO addin you should never use CreateObject to instantiate an
Outlook.Application object. Instead in the Startup event do this:

myOlApp = Me.Application


Also, change your declaration of the ItemSend event handler to this:

Private Sub myOlApp_ItemSend(ByVal Item As Object, _
ByVal Cancel As Boolean) Handles myOlApp.ItemSend

See if that helps.
 
S

sophie

Thanks for your help, Ken.
I have worked out.
BTW, Private Sub myOlApp_ItemSend(ByVal Item As Object, _
ByVal Cancel As Boolean) Handles myOlApp.ItemSend
should be (ByVal Item As Object, ByRef Cancel As Boolean)
 
K

Ken Slovak - [MVP - Outlook]

So it should be, thanks for the correction. I just copied your original
event signature and didn't bother to actually study it closely.
 
B

Bala

Hi,

I am using the below code to prompt a message n the item send event. But the
control is no going to the MsgBox directly, instead i have to toggle the
screen to see the message box.

How i could able to bring up the message box in top of all by outlook pages?
Thanks for your help

Private Sub myOlAppEvents_ItemSend(ByVal Item As Object, ByVal Cancel As
Boolean)
Dim prompt As String
prompt = "Are you sure you want to send mail with out the subject ?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If

End Sub


Regrds,
Bala.
 
K

Ken Slovak - [MVP - Outlook]

Please do not hijack threads, start your own.

You can't control the z-order or parent/child relationship of a MsgBox
unless you use Win32 API calls to get the handle of that dialog and make it
the topmost window or make it child of the current foreground window and
then set the z-order using Win32 API calls.
 

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