Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Email this linkEmail this link Printer-Friendly VersionPrinter-Friendly Version Bookmark and ShareShare
Add a last contacted date to your Outlook 2002 contacts
 
Power User Corner

By Paul Cornell

How can you record the date you last spoke with or sent e-mail to someone in your Outlook 2002 Contacts list? In this article, you will learn how to create an Outlook macro that adds a last contacted date to one of your contacts.

Applies to
Microsoft Outlook® 2002


See all Power User columns
See all columns

I occasionally use the Journal feature in Microsoft Outlook® 2002 to associate e-mail messages, meeting items, task items, and Office files with my contacts. I sometimes create individual Journal items and associate them with individual contacts as well. However, sometimes I want to quickly make a note of when I last contacted someone without taking the time to create a complete Journal item. The following steps enable you to quickly make a tick mark that notes when you last spoke with or sent e-mail to one of your Outlook contacts.

To create a macro to add a last contacted date to an Outlook 2002 contact

  1. From inside Outlook, open the Microsoft Office Visual Basic® Editor. (On the Tools menu, point to Macro, and then click Visual Basic Editor.)
  2. If the Project Explorer window is not visible, on the View menu, click Project Explorer.
  3. In the Project Explorer window, expand the folder tree to open the Microsoft Outlook Objects folder, and then double-click ThisOutlookSession.
  4. Type the following code into the Code window (the large, blank window on the right side of the screen):
    Public Sub LastContacted()
    
        ' Purpose: Adds a "Last Contacted" property to
        ' the active contact item.
        ' Note: You must select a contact item before
        ' running this macro.
        
        Dim olApp As Outlook.Application
        Dim oSel As Outlook.Selection
        Dim oContact As Outlook.ContactItem
        Dim oPrp As Outlook.ItemProperty
        Dim bFieldExists As Boolean
        
        Const FIELD_NAME As String = "Last Contacted"
        
        On Error GoTo LastContacted_Err
        
        Set olApp = Outlook.Application
        Set oSel = olApp.ActiveExplorer.Selection
            
        ' Only one item can be selected.
        If oSel.Count > 1 Then
        
            MsgBox "You selected more than one item. " & _
                "Select only one item and try again."
            Exit Sub
            
        End If
        
        ' Selected item must be a contact item.
        Set oContact = oSel.Item(1)
            
        ' Check for a custom "Last Contacted" field.
        For Each oPrp In oContact.ItemProperties
            
            If oPrp.Name = FIELD_NAME Then
                
                bFieldExists = True
                oPrp.Value = Now
                MsgBox FIELD_NAME & " property updated."
                
            End If
        
        Next oPrp
            
        ' Create "Last Contacted" field if it doesn't already exist.
        If bFieldExists = False Then
            
            Set oPrp = _
                oContact.ItemProperties.Add(FIELD_NAME, olDateTime)
            
            oPrp.Value = Now
            MsgBox FIELD_NAME & " property created and updated."
            
        End If
        
        oContact.Save
        
    LastContacted_End:
    
        Set oPrp = Nothing
        Set oContact = Nothing
        Set oSel = Nothing
        Set olApp = Nothing
        
        Exit Sub
    
    LastContacted_Err:
    
        Select Case Err.Number
            
            Case 13 ' Not a contact item.
          
                MsgBox "You can only run this macro on contact " & _
                    "items. Select one contact item and try again."
            
            Case Else   ' Unanticipated error.
            
                MsgBox "Error " & Err.Number & " in LastContacted " & _
                    "subroutine: " & Err.Description
                    
        End Select
        
        Resume LastContacted_Err
    
    End Sub
    

  5. On the File menu, click Close and Return to Microsoft Outlook.

To run the macro

  1. Open your Outlook Contacts folder.
  2. Select a single contact item (do not open the contact item).
  3. On the Tools menu, point to Macro, and then click Macros.
  4. Click LastContacted, and then click Run.
  5. Click OK when the dialog box appears.
  6. Open the selected Outlook contact item.
  7. On the All Fields tab, in the Select from list, click User-defined fields in this item.

The Last Contacted field appears along with the date and time you ran the LastContacted macro. Be sure to run this macro at or near the time you make your call or send e-mail, so that the date and time entered by the macro are correct.

If you're willing to learn a little more about how this macro functions technically, you can modify it to create additional user-defined fields. For more information, see these resources on the Microsoft Developer Network (MSDN):

Keep sending that e-mail!

We look forward to receiving your e-mail messages at pwruser@microsoft.com. We really want this to be your column, so please send us your comments and favorite handcrafted Office solutions. Remember, we will not be able to feature every Office solution that we receive, we will not have the time to respond to all of your e-mail, and we are not technical support representatives. But we may feature your solution in an upcoming column.


About the author

Paul Cornell works for the Office Help team. In addition to writing the Office Power User Corner column, Paul contributes to the Office Talk column on the Microsoft Developer Network (MSDN). He is the author of the book Accessing and Analyzing Data with Microsoft Excel.

If you like this column and want to hear about more fun and useful Office offerings, sign up for our newsletter.

See all Power User columns
See all columns
© 2009 Microsoft Corporation. All rights reserved.