Automatically send message when contact is saved

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'd like to automatically send a message when I saved a new contact or when
I update it.
That message would contain the new/updated contact.
Do you have any hint on how to "recode" the "Save Contact" button ?
I already have a command bar on which I could add a button that would do
both, but how to code this ?

Any help is welcome. Thanks in advance.

Pascal
 
Add the code below to your ThisOutlookSession module. It should meet your
needs; tweak it if it doesn't!

You don't have to use a custom button for this sample. It'll send the
Contact as an attachment to a new e-mail message upon close, if it detects
that the Contact was saved.

Note that Outlook versions greater than 2000 or with the E-mail Security
Update will get prompted to send the message. See
http://www.slipstick.com/outlook/esecup.htm#autosec for more info.

Also, be careful about how many newsgroups you cross-post to. There's
usually only one or two groups max that is applicable to any given question.

Option Explicit
Dim WithEvents objInspectors As Inspectors
Dim WithEvents objContactItem As Outlook.ContactItem
Dim blnContactChanged As Boolean

Private Sub Application_Startup()
Set objInspectors = Application.Inspectors
End Sub

Private Sub Application_Quit()
Set objInspectors = Nothing
Set objContactInspector = Nothing
End Sub

Private Sub objContactItem_Close(Cancel As Boolean)
If blnContactChanged Then
SendEmailWithUpdatedContact
End If
blnContactChanged = False
End Sub

Private Sub objContactItem_Write(Cancel As Boolean)
blnContactChanged = True
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class <> olContact Then Exit Sub
Set objContactItem = Inspector.CurrentItem
End Sub

Sub SendEmailWithUpdatedContact()
Dim objMailItem As Outlook.MailItem

Set objMailItem = Application.CreateItem(olMailItem)
objMailItem.Attachments.Add objContactItem, olByValue
objMailItem.Subject = "Updated contact"
objMailItem.To = "(e-mail address removed)"
objMailItem.Send
End Sub
 
it helped, it is part of the answer..
thanks.


Eric Legault said:
Add the code below to your ThisOutlookSession module. It should meet your
needs; tweak it if it doesn't!

You don't have to use a custom button for this sample. It'll send the
Contact as an attachment to a new e-mail message upon close, if it detects
that the Contact was saved.

Note that Outlook versions greater than 2000 or with the E-mail Security
Update will get prompted to send the message. See
http://www.slipstick.com/outlook/esecup.htm#autosec for more info.

Also, be careful about how many newsgroups you cross-post to. There's
usually only one or two groups max that is applicable to any given question.

Option Explicit
Dim WithEvents objInspectors As Inspectors
Dim WithEvents objContactItem As Outlook.ContactItem
Dim blnContactChanged As Boolean

Private Sub Application_Startup()
Set objInspectors = Application.Inspectors
End Sub

Private Sub Application_Quit()
Set objInspectors = Nothing
Set objContactInspector = Nothing
End Sub

Private Sub objContactItem_Close(Cancel As Boolean)
If blnContactChanged Then
SendEmailWithUpdatedContact
End If
blnContactChanged = False
End Sub

Private Sub objContactItem_Write(Cancel As Boolean)
blnContactChanged = True
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class <> olContact Then Exit Sub
Set objContactItem = Inspector.CurrentItem
End Sub

Sub SendEmailWithUpdatedContact()
Dim objMailItem As Outlook.MailItem

Set objMailItem = Application.CreateItem(olMailItem)
objMailItem.Attachments.Add objContactItem, olByValue
objMailItem.Subject = "Updated contact"
objMailItem.To = "(e-mail address removed)"
objMailItem.Send
End Sub
 
Back
Top