Capturing Contact Create or Open Event - Is There a Better Way?
Hi all,
This is for an Outlook Add-in using Visual Basic 6.
I'm trying to capture when a contact is opened, created, or saved. Let's just go with opened for now, however.
I have the following code which works, but I'm wondering if there is a better way to do this.
The following code is in the Connect.dsr of the add-in project.
VB6 Code:
Private WithEvents objContact As Outlook.ContactItem
Private WithEvents objExplorer As Outlook.Explorer
Private WithEvents objOLApp As Outlook.Application
Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
'Set my object to the host application.
Set objOLApp = Outlook.Application
Set objExplorer = Outlook.ActiveExplorer
End Sub
Private Sub objExplorer_SelectionChange()
'Custom Function to see if current folder is a contact folder
If IsContactFolder = False Then Exit Sub
Dim objSel As Outlook.Selection
If objExplorer.Selection.Count = 1 Then
Set objSel = objExplorer.Selection
If objSel.Count = 1 Then
If TypeName(objSel.Item(1)) = "ContactItem" Then
Set objContact = objSel.Item(1)
End If
End If
End If
End Sub
If there is a better way to do this, please respond. I'd greatly appreciate it.
Actually, if this is the best way, please confirm that it is so I can move on. :)
Thanks,
JB