ItemSend event not firing

Status
Not open for further replies.
P

PatrickS

I have a support tool that I'm supposed to be maintaining. I'd like to be

able to have a button on the support call form that opens up an email in

Outlook (at this stage I can assume that it will only be Outlook

2000/2002/2003 being used) and then when the email is sent have the contents

of the email added as a note to the support call in the database.

I created a dummy VB project using VB6 to make sure I could do what I wanted

in this regard. I added a button to the form that creates a new instance of a

class and then calls the SendSupportMail() method. The contents of this class

are included below, however neither the ItemSend nor the Send events are

fired even though the emails themselves are successfully sent. Breakpoints

that I've added on the Msgbox statements are never reached.

What am I doing wrong?

--------------------------------------------------------Private WithEvents objApp As Outlook.Application

Private WithEvents objMail As Outlook.MailItem

Private Sub Class_Initialize()

Set objApp = Outlook.Application

End Sub

Private Sub objApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

MsgBox "Test"

End Sub

Public Sub SendSupportMail()

Set objMail = objApp.CreateItem(olMailItem)

objMail.Display

End Sub

Private Sub objMail_Send(Cancel As Boolean)

MsgBox "Test2"

End Sub
 
So your button click instantiates an instance of this class and calls the

SendSupportMail() method and then the button click event handler ends?

If that's the case, the class instance is going out of scope at the point

where the click event handler ends. So at that time the Send() and

ItemSend() event handlers have already been released and can't fire.

How is this button created? Is it created in your VB6 code? Where does that

code reside? If it's in another part of your VB6 code then add a reference

to the class you create at a module level that will retain scope so the

event handlers continue to fire. Something like this:

' at module level in module where button click handler resides

Dim myClass As WhateverTheClassIsCalled

' in button click handler

Set myClass = New WhateverTheClassIsCalled

That way as long as the module has scope the class will have scope and the

events should fire.

"PatrickS" <msdn_newsgroups001@_removetextplusunderscores_seurre.com.> wrote

in message news:99065991-F13C-4FC8-A75B-2A35C9B4A17C@microsoft.com...
> I have a support tool that I'm supposed to be maintaining. I'd like to be
> able to have a button on the support call form that opens up an email in
> Outlook (at this stage I can assume that it will only be Outlook
> 2000/2002/2003 being used) and then when the email is sent have the
> contents
> of the email added as a note to the support call in the database.

> I created a dummy VB project using VB6 to make sure I could do what I
> wanted
> in this regard. I added a button to the form that creates a new instance
> of a
> class and then calls the SendSupportMail() method. The contents of this
> class
> are included below, however neither the ItemSend nor the Send events are
> fired even though the emails themselves are successfully sent. Breakpoints
> that I've added on the Msgbox statements are never reached.

> What am I doing wrong?

> --------------------------------------------------------> Private WithEvents objApp As Outlook.Application
> Private WithEvents objMail As Outlook.MailItem

> Private Sub Class_Initialize()
> Set objApp = Outlook.Application
> End Sub

> Private Sub objApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
> MsgBox "Test"
> End Sub

> Public Sub SendSupportMail()
> Set objMail = objApp.CreateItem(olMailItem)
> objMail.Display
> End Sub

> Private Sub objMail_Send(Cancel As Boolean)
> MsgBox "Test2"
> End Sub
 
D'oh! I'd made the stupid mistake of having the class variable declared

inside the event handler for the button. Moving that declaration outside the

click event handler appears to have fixed the problem. Now both message boxes

are appearing.

Thank you for your time.
wrote:


> So your button click instantiates an instance of this class and calls the
> SendSupportMail() method and then the button click event handler ends?

> If that's the case, the class instance is going out of scope at the point
> where the click event handler ends. So at that time the Send() and
> ItemSend() event handlers have already been released and can't fire.

> How is this button created? Is it created in your VB6 code? Where does that
> code reside? If it's in another part of your VB6 code then add a reference
> to the class you create at a module level that will retain scope so the
> event handlers continue to fire. Something like this:

> ' at module level in module where button click handler resides
> Dim myClass As WhateverTheClassIsCalled

> ' in button click handler
> Set myClass = New WhateverTheClassIsCalled

> That way as long as the module has scope the class will have scope and the
> events should fire.

> >

>

> "PatrickS" <msdn_newsgroups001@_removetextplusunderscores_seurre.com.> wrote
> in message news:99065991-F13C-4FC8-A75B-2A35C9B4A17C@microsoft.com...
> >I have a support tool that I'm supposed to be maintaining. I'd like to be
> > able to have a button on the support call form that opens up an email in
> > Outlook (at this stage I can assume that it will only be Outlook
> > 2000/2002/2003 being used) and then when the email is sent have the
> > contents
> > of the email added as a note to the support call in the database.
> > I created a dummy VB project using VB6 to make sure I could do what I
> > wanted
> > in this regard. I added a button to the form that creates a new instance
> > of a
> > class and then calls the SendSupportMail() method. The contents of this
> > class
> > are included below, however neither the ItemSend nor the Send events are
> > fired even though the emails themselves are successfully sent. Breakpoints
> > that I've added on the Msgbox statements are never reached.
> > What am I doing wrong?
> > --------------------------------------------------------------------------------------> > Private WithEvents objApp As Outlook.Application
> > Private WithEvents objMail As Outlook.MailItem
> > Private Sub Class_Initialize()
> > Set objApp = Outlook.Application
> > End Sub
> > Private Sub objApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
> > MsgBox "Test"
> > End Sub
> > Public Sub SendSupportMail()
> > Set objMail = objApp.CreateItem(olMailItem)
> > objMail.Display
> > End Sub
> > Private Sub objMail_Send(Cancel As Boolean)
> > MsgBox "Test2"
> > End Sub


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Looking for email address under ItemSend event Outlook VBA and Custom Forms 6
E Properties added to MailItem in ItemSend event visible to recipien Outlook VBA and Custom Forms 1
T Hooking up the ItemSend Event... Outlook VBA and Custom Forms 1
E When more than "ItemSend" is needed Using Outlook 5
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using Outlook.com accounts in Outlook 0
T How to get an EVENT COLOR option in Outlook 2021 ? Using Outlook 0
J Cannot edit a calendar event received as an invitation Using Outlook 2
T Event Error on non existent Event. Using Outlook 2
J Event/Meeting in Outlook Does Not Align with SharePoint Calendar Using Outlook 5
P Calendar Day View only shows 1 all day event Using Outlook 0
G Event when creating task from mailitem Outlook VBA and Custom Forms 2
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
J Outlook 2010 Outlook/Win7 Client logging Event ID 36887 Using Outlook 0
K Recurring all day annual event Using Outlook 3
P Restore an individual all-day recurring event Using Outlook 2
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
K Working with Explorer.Close event Outlook VBA and Custom Forms 3
F Outlook 2016 call to Stop Timer Event Outlook VBA and Custom Forms 4
D Event ID issues Exchange Server Administration 2
J ItemChange event Outlook VBA and Custom Forms 11
T Outlook 2016 Calendar multiday event display Using Outlook 4
oliv- Treat once an email with the ItemAdd event in a shared mailbox Outlook VBA and Custom Forms 2
M Automatically create event in calendar when task is created Outlook VBA and Custom Forms 1
A UID field in iCal files - unique per-event or per-user or both? Using Outlook 2
D help with Item/Inspector close event Outlook VBA and Custom Forms 1
B on flag message event - create task Outlook VBA and Custom Forms 22
Diane Poremsky Change the All Day Event Default Free/Busy to "Busy" Using Outlook 3
C Calendar - Centering an event in Outlook? Using Outlook 1
J Outlook calendar...How to add an event or appointment without a border around it? Using Outlook 9
J Create Calendar Alert Event form Mail Subject line? Using Outlook 4
S Item Add Event fires intermittently Outlook VBA and Custom Forms 3
R Why is a meeting organizer me and not the creator of the event? Using Outlook 1
V Calendar event acting odd Using Outlook 7
G Capture "forward event" ? Outlook VBA and Custom Forms 11
P Change the Outlook.com "from" address for calendar event invites Using Outlook 9
20 Ton Squirrel Detect Application_Startup event completion Outlook VBA and Custom Forms 1
L Outlook 2007 All Day Event Using Outlook 27
I Event listener for deleted items Using Outlook 6
M Save Attachments Event? Using Outlook 0
Commodore Calendar Folder property is missing - Event 27 Using Outlook 11
G Quit event code - 2007 Using Outlook 3
J Capturing forward event when multiple items are selected Using Outlook 0
P Trying to get 'Calendar Name' to appear like 'Subject' and 'Location' in event Using Outlook 0
G What event happens when you open 2 copies of your inbox? Using Outlook 5
D Adding a participant automatically to a calendar event Using Outlook 1
H Changing Organizer of event (for single to total calendar move; long way ) Exchange Server Administration 4
N Combobox in outlook add ons toolbar not firing event on main window resized Using Outlook 3
D Extracting Location info from All Day Event in mailboxes into webpage Exchange Server Administration 3
H Conflicts with other event in calendar ( outlook 2007 &amp; 2010) Using Outlook 0
B Restoring Deleted Recurring Event AND Notes Using Outlook 8

Similar threads

Back
Top