Microsoft KB Archive/260999

= How To OL98: Work with Linked Contacts of Outlook Items Using the Outlook Object Model - Visual Basic =

Article ID: 260999

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Outlook 98 Standard Edition
 * Microsoft Office 97 Standard Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q260999



SUMMARY
This article demonstrates how to work with linked contact items that are associated with task and journal items by using the Outlook Object Model. The process is enhanced in Outlook 2000 by the addition of the Links collection.



MORE INFORMATION
Outlook 97 or 98 Object Library

Use the Recipients collection of task and journal items to add new linked contacts.

Use the ContactNames property to retrieve a delimited list of the display names for the linked contacts. To obtain the actual contact item, you must iterate and manually search all contacts to find a match. The following code demonstrates how to do this: Private Sub AddLinkedContactToTask Dim spOutlook As Outlook.Application Dim spNameSpace As Outlook.NameSpace Dim spTasksFolder As MAPIFolder Dim spTasks As Items Dim spTask As TaskItem Dim spContactsFolder As MAPIFolder Dim spContacts As Items Dim spContact As ContactItem Dim spRecips As Recipients Dim spRecip As Recipient Dim s As String, sContact As String, s2 As String Dim i As Long, j As Long On Error GoTo Handler Set spOutlook = CreateObject(&quot;Outlook.Application&quot;) If spOutlook Is Nothing Then Exit Sub Set spNameSpace = spOutlook.GetNamespace(&quot;MAPI&quot;) 'Get tasks folder. Set spTasksFolder = spNameSpace.GetDefaultFolder(olFolderTasks) Set spContactsFolder = spNameSpace.GetDefaultFolder(olFolderContacts) Set spTasks = spTasksFolder.Items 'Get first taskitem. Set spTask = spTasks.GetFirst Debug.Print spTask.Subject 'Add new linked contact. Set spRecips = spTask.Recipients Set spRecip = spRecips.Add(&quot;Contact Name&quot;) spRecip.Resolve spTask.Save 'Loop through contact names. Set spContacts = spContactsFolder.Items ' Get a list of the contact names. s = spTask.ContactNames Debug.Print s   If Len(s) > 0 Then i = 1: j = 1 Do Until i = 0 i = InStr(j, s, &quot;;&quot;) If i > 0 Then sContact = Mid$(s, j, i - j)              j = i + 1 Else sContact = Mid$(s, j)          End If           s2 = &quot;[FileAs] = &quot; & Chr$(34) & sContact & Chr$(34) Set spContact = spContacts.Find(s2) If Not spContact Is Nothing Then Debug.Print spContact.FullName End If          Set spContact = Nothing Loop End If Done: Set spRecip = Nothing Set spRecips = Nothing Set spTask = Nothing Set spTasks = Nothing Set spTasksFolder = Nothing Set spContact = Nothing Set spContacts = Nothing Set spContactsFolder = Nothing Set spNameSpace = Nothing Set spOutlook = Nothing Exit Sub Handler: Resume Done End Sub

Outlook 2000 Object Library

Use the Links collection of task and journal items to add and retrieve linked contacts.

NOTE: When you use Outlook 2000, items that were created with Outlook 97 or Outlook 98 may contain valid data in the Recipients collection and ContactNames property; however, these properties do not contain valid data in items that are created with Outlook 2000.

