PC Review


Reply
Thread Tools Rate Thread

Capture Outlook Items' events in VBA?

 
 
John Riddle
Guest
Posts: n/a
 
      7th Jul 2005
Hello,

I'm trying to replace the code behind my Outlook forms with VBA code, but am
having trouble capturing the events. Here's what I've got so far:

Public WithEvents VBAInspectors As Inspectors
Public WithEvents VBAInspector As Inspector
Public WithEvents VBAContact As ContactItem

Private Sub Initialize_Handler()
Set VBAInspectors = Application.Inspectors
End Sub

Private Sub Application_Startup()
Initialize_Handler
End Sub

Private Sub VBAContact_Open(Cancel As Boolean)
MsgBox "Item Opened"
End Sub

Private Sub VBAInspector_Activate()
Set objItem = VBAInspector.CurrentItem
If objItem.MessageClass = "IPM.Contact" Then
Set VBAContact = VBAInspector.CurrentItem
MsgBox VBAContact.FullName
Else
Set VBAContact = Nothing
End If
End Sub

Private Sub VBAInspectors_NewInspector(ByVal Inspector As Inspector)
Set VBAInspector = Inspector
End Sub

The "MsgBox VBAContact.FullName executes fine, but the "Item Opened" message
in the VBAContact_Open event does not fire.

Any suggestions?

Thanks,

John


 
Reply With Quote
 
 
 
 
Michael Bauer
Guest
Posts: n/a
 
      8th Jul 2005
John, in VBAInspector_Activate itīs too late, the item is opened
already. Use the NewInspector event instead.


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook



John Riddle wrote:
> Hello,
>
> I'm trying to replace the code behind my Outlook forms with VBA code,
> but am having trouble capturing the events. Here's what I've got so
> far:
>
> Public WithEvents VBAInspectors As Inspectors
> Public WithEvents VBAInspector As Inspector
> Public WithEvents VBAContact As ContactItem
>
> Private Sub Initialize_Handler()
> Set VBAInspectors = Application.Inspectors
> End Sub
>
> Private Sub Application_Startup()
> Initialize_Handler
> End Sub
>
> Private Sub VBAContact_Open(Cancel As Boolean)
> MsgBox "Item Opened"
> End Sub
>
> Private Sub VBAInspector_Activate()
> Set objItem = VBAInspector.CurrentItem
> If objItem.MessageClass = "IPM.Contact" Then
> Set VBAContact = VBAInspector.CurrentItem
> MsgBox VBAContact.FullName
> Else
> Set VBAContact = Nothing
> End If
> End Sub
>
> Private Sub VBAInspectors_NewInspector(ByVal Inspector As Inspector)
> Set VBAInspector = Inspector
> End Sub
>
> The "MsgBox VBAContact.FullName executes fine, but the "Item Opened"
> message in the VBAContact_Open event does not fire.
>
> Any suggestions?
>
> Thanks,
>
> John



 
Reply With Quote
 
John Riddle
Guest
Posts: n/a
 
      8th Jul 2005
Okay. I tried that already but when doing it that way, I have no way to keep
track of multiple open contacts. That's to say, switching between one contact
and another does not fire the VBAInspector_Activate event. How can I work with
several contacts switching between them and still fire the events...
propertychange, custompropertychange, etc.?

I have about 1000 lines of code behind my custom contact form and I need to
move this to a VBA module for the moment and then once I verify that
everything is working properly, I'll work on converting it to a Com Addin.

Thanks,

John
"Michael Bauer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
John, in VBAInspector_Activate itīs too late, the item is opened
already. Use the NewInspector event instead.


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook



John Riddle wrote:
> Hello,
>
> I'm trying to replace the code behind my Outlook forms with VBA code,
> but am having trouble capturing the events. Here's what I've got so
> far:
>
> Public WithEvents VBAInspectors As Inspectors
> Public WithEvents VBAInspector As Inspector
> Public WithEvents VBAContact As ContactItem
>
> Private Sub Initialize_Handler()
> Set VBAInspectors = Application.Inspectors
> End Sub
>
> Private Sub Application_Startup()
> Initialize_Handler
> End Sub
>
> Private Sub VBAContact_Open(Cancel As Boolean)
> MsgBox "Item Opened"
> End Sub
>
> Private Sub VBAInspector_Activate()
> Set objItem = VBAInspector.CurrentItem
> If objItem.MessageClass = "IPM.Contact" Then
> Set VBAContact = VBAInspector.CurrentItem
> MsgBox VBAContact.FullName
> Else
> Set VBAContact = Nothing
> End If
> End Sub
>
> Private Sub VBAInspectors_NewInspector(ByVal Inspector As Inspector)
> Set VBAInspector = Inspector
> End Sub
>
> The "MsgBox VBAContact.FullName executes fine, but the "Item Opened"
> message in the VBAContact_Open event does not fire.
>
> Any suggestions?
>
> Thanks,
>
> John




 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      8th Jul 2005
John, to handle multiple Inspectors or Explorers you need a wrapper class.
That class handles all the events for the Inspector or Explorer and is put
into a collection to keep the reference alive. See
http://www.slovaktech.com/code_sampl...spectorWrapper for an example
of a VB 6 Inspector wrapper. The ItemsCB VB 6 sample on the Resources page
at www.microeye.com has an example of an Explorer wrapper in it.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"John Riddle" <jriddleatsignwilsongroupnyperiodcom> wrote in message
news:ulMHPO$(E-Mail Removed)...
> Okay. I tried that already but when doing it that way, I have no way to
> keep
> track of multiple open contacts. That's to say, switching between one
> contact
> and another does not fire the VBAInspector_Activate event. How can I work
> with
> several contacts switching between them and still fire the events...
> propertychange, custompropertychange, etc.?
>
> I have about 1000 lines of code behind my custom contact form and I need
> to
> move this to a VBA module for the moment and then once I verify that
> everything is working properly, I'll work on converting it to a Com Addin.
>
> Thanks,
>
> John


 
Reply With Quote
 
John Riddle
Guest
Posts: n/a
 
      12th Jul 2005
Ken,

Thanks! That worked great. Now I have an issue where events are firing
multiple times (once for each time the item as been opened).

For example, if I put the statement

MsgBox "I'm open"

into the m_objContact_Open() event, it fires once the first time. The next
time I open the item, I get two message boxes, the third time I get three of
them and so on...

Any idea what I might have done wrong?

Thanks,

John

"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:%23hh8Gc$(E-Mail Removed)...
John, to handle multiple Inspectors or Explorers you need a wrapper class.
That class handles all the events for the Inspector or Explorer and is put
into a collection to keep the reference alive. See
http://www.slovaktech.com/code_sampl...spectorWrapper for an example
of a VB 6 Inspector wrapper. The ItemsCB VB 6 sample on the Resources page
at www.microeye.com has an example of an Explorer wrapper in it.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"John Riddle" <jriddleatsignwilsongroupnyperiodcom> wrote in message
news:ulMHPO$(E-Mail Removed)...
> Okay. I tried that already but when doing it that way, I have no way to
> keep
> track of multiple open contacts. That's to say, switching between one
> contact
> and another does not fire the VBAInspector_Activate event. How can I work
> with
> several contacts switching between them and still fire the events...
> propertychange, custompropertychange, etc.?
>
> I have about 1000 lines of code behind my custom contact form and I need
> to
> move this to a VBA module for the moment and then once I verify that
> everything is working properly, I'll work on converting it to a Com Addin.
>
> Thanks,
>
> John



 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      12th Jul 2005
It sounds like you aren't using unique Key properties for each item in the
wrapper class collection. Just like with custom command bar buttons where a
unique Tag property is required to prevent a button click from firing in
each Inspector that is open you need to use unique Key properties for an
Inspector wrapper.

Also, make sure each Inspector wrapper class is released and removed from
the Inspectors wrapper collection when the Inspector is closed.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"John Riddle" <jriddleatsignwilsongroupnyperiodcom> wrote in message
news:%(E-Mail Removed)...
> Ken,
>
> Thanks! That worked great. Now I have an issue where events are firing
> multiple times (once for each time the item as been opened).
>
> For example, if I put the statement
>
> MsgBox "I'm open"
>
> into the m_objContact_Open() event, it fires once the first time. The next
> time I open the item, I get two message boxes, the third time I get three
> of
> them and so on...
>
> Any idea what I might have done wrong?
>
> Thanks,
>
> John


 
Reply With Quote
 
John Riddle
Guest
Posts: n/a
 
      12th Jul 2005
After going through the code very closely to see what was happening, I figured
out that I had named my regular module "OutlInsp" instead of "basOutlInsp"
like your instructions stated. I simply changed the line:

basOutlInsp.KillInsp m_intID, Me

To:

KillInsp m_intID, Me

and everything works great now.

Thanks!

John


"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:%23hh8Gc$(E-Mail Removed)...
John, to handle multiple Inspectors or Explorers you need a wrapper class.
That class handles all the events for the Inspector or Explorer and is put
into a collection to keep the reference alive. See
http://www.slovaktech.com/code_sampl...spectorWrapper for an example
of a VB 6 Inspector wrapper. The ItemsCB VB 6 sample on the Resources page
at www.microeye.com has an example of an Explorer wrapper in it.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"John Riddle" <jriddleatsignwilsongroupnyperiodcom> wrote in message
news:ulMHPO$(E-Mail Removed)...
> Okay. I tried that already but when doing it that way, I have no way to
> keep
> track of multiple open contacts. That's to say, switching between one
> contact
> and another does not fire the VBAInspector_Activate event. How can I work
> with
> several contacts switching between them and still fire the events...
> propertychange, custompropertychange, etc.?
>
> I have about 1000 lines of code behind my custom contact form and I need
> to
> move this to a VBA module for the moment and then once I verify that
> everything is working properly, I'll work on converting it to a Com Addin.
>
> Thanks,
>
> John



 
Reply With Quote
 
John Riddle
Guest
Posts: n/a
 
      13th Jul 2005
Ken,

I mostly have everything working now. Except in my custom form, the Item_Read
event would fire when the item was selected in a view. However, now that I've
ported my code over to VBA, the Read event only fires when the item is
double-clicked (opened). How can I get a read event to fire from VBA when an
item in a folder is selected and previewed?

Thanks for all your help!

John


"Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
It sounds like you aren't using unique Key properties for each item in the
wrapper class collection. Just like with custom command bar buttons where a
unique Tag property is required to prevent a button click from firing in
each Inspector that is open you need to use unique Key properties for an
Inspector wrapper.

Also, make sure each Inspector wrapper class is released and removed from
the Inspectors wrapper collection when the Inspector is closed.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"John Riddle" <jriddleatsignwilsongroupnyperiodcom> wrote in message
news:%(E-Mail Removed)...
> Ken,
>
> Thanks! That worked great. Now I have an issue where events are firing
> multiple times (once for each time the item as been opened).
>
> For example, if I put the statement
>
> MsgBox "I'm open"
>
> into the m_objContact_Open() event, it fires once the first time. The next
> time I open the item, I get two message boxes, the third time I get three
> of
> them and so on...
>
> Any idea what I might have done wrong?
>
> Thanks,
>
> John



 
Reply With Quote
 
Michael Bauer
Guest
Posts: n/a
 
      14th Jul 2005
John,

in that case use the SelectionChange event and check if
ActiveExplorer.IsPaneVisible(olPreview)=True.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook



John Riddle wrote:
> Ken,
>
> I mostly have everything working now. Except in my custom form, the
> Item_Read event would fire when the item was selected in a view.
> However, now that I've ported my code over to VBA, the Read event
> only fires when the item is double-clicked (opened). How can I get a
> read event to fire from VBA when an item in a folder is selected and
> previewed?
>
> Thanks for all your help!
>
> John
>
>
> "Ken Slovak - [MVP - Outlook]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> It sounds like you aren't using unique Key properties for each item
> in the wrapper class collection. Just like with custom command bar
> buttons where a unique Tag property is required to prevent a button
> click from firing in each Inspector that is open you need to use
> unique Key properties for an Inspector wrapper.
>
> Also, make sure each Inspector wrapper class is released and removed
> from the Inspectors wrapper collection when the Inspector is closed.
>
>
> "John Riddle" <jriddleatsignwilsongroupnyperiodcom> wrote in message
> news:%(E-Mail Removed)...
>> Ken,
>>
>> Thanks! That worked great. Now I have an issue where events are
>> firing multiple times (once for each time the item as been opened).
>>
>> For example, if I put the statement
>>
>> MsgBox "I'm open"
>>
>> into the m_objContact_Open() event, it fires once the first time.
>> The next time I open the item, I get two message boxes, the third
>> time I get three of
>> them and so on...
>>
>> Any idea what I might have done wrong?
>>
>> Thanks,
>>
>> John


 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      14th Jul 2005
As Michael suggested, you could use SelectionChange of an Explorer object.
Item_Read won't fire for an Inspector wrapper class since the item hasn't
been opened and therefore there is no Inspector for it.

A tricky workaround that actually handles the original Item_Read even would
be to check the Explorer's Selection collection and each time it changed
check the count. If it's 1 then instantiate a MailItem (or other type
depending on the Class of the selected object) and declare for that MailItem
WithEvents declarations for any events you want to handle such as Read.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"John Riddle" <jriddleatsignwilsongroupnyperiodcom> wrote in message
news:u2d1Ey%(E-Mail Removed)...
> Ken,
>
> I mostly have everything working now. Except in my custom form, the
> Item_Read
> event would fire when the item was selected in a view. However, now that
> I've
> ported my code over to VBA, the Read event only fires when the item is
> double-clicked (opened). How can I get a read event to fire from VBA when
> an
> item in a folder is selected and previewed?
>
> Thanks for all your help!
>
> John


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
outlook add-in, add-in for outlook, outlook contact capture, capturecontacts into outlook, outlook add-on, address capture, capture name,addresses, import contacts to Outlook, transfer contact details into outlook Dhan Microsoft Outlook Program Addins 0 24th Apr 2010 09:03 AM
how to capture outlook 2007 events Ashish Microsoft Outlook Program Addins 4 29th Jul 2009 03:20 PM
Can Flagged items pop-up just like Task Items or Calendar Events? =?Utf-8?B?U2hhZG93bWFuMTM=?= Microsoft Outlook Discussion 1 4th May 2006 10:02 AM
Capture FTP events =?Utf-8?B?QnJpYW4=?= Microsoft Access VBA Modules 1 16th Feb 2006 04:43 PM
Re: capture all events? Martin R-L Microsoft VB .NET 0 27th Apr 2004 03:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:59 PM.