Adding an event handler for Outlook using VB (not VBA)

T

Ted Byers

In my COM AddIn class, I have a declaration,in a VB project) as follows:

Private WithEvents objContactItem As Outlook.ContactItem

As I understand it, this allows me to be notified that events associated
with editing, adding or deleting a ContactItem have occured. The question
is, "How do I add the event handler?" Is it to be a member function of my
COM class, or a separate function, and how do I ensure that my function is
called? (I.e., I know how to add a function to a class, but I don't know
how to tell Outlook which function to call for any given event.) While I
expect this to be as simple as creating a callback function and passing the
pointer to Outlook, or even as simple as adding a member function to my
class with an appropriate name, but then the question is what name. I have
yet to find this documented anywhere.

I guess there is another question, in that I need to know how objContactItem
is initialized. I need to do so in two contexts. In one case, I will have
contact information and I will need to first put that information into
either a new ContactItem (in the case of adding a contact) or into an
existing ContactItem (in the case of an edit) in which case I'd need to be
able to find the right contact already in the Outlook database in order to
make the edit. In the second case, I will need to retrieve the new contact
data associated with an edit or add event.

This must be simple to do, but I haven't found what I need to know in the
documentation I have.

Any assistance will be greatly appreciated.

Thanks

Ted
 
N

Norm Cook

If I understand you question correctly, assuming you have added a reference
to the Outlook Object Library and also assuming this statement was added to
a form or class module
Private WithEvents objContactItem As Outlook.ContactItem

If you will drop down the left hand combo box at the top of the code module,
you should find
objContactItem in the list. Click on that and the default event will appear
in your code module. Now if you drop down the right hand combo, you will
see all the other available events.
 

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