Run Time Error 91 when linking contact to task in VBA

Status
Not open for further replies.
Outlook version
Outlook 2010 32 bit
Email Account
Office 365 Exchange
#1
I have a piece of code that creates a task then links a specified contact to the task. It worked fine in Outlook 2010, however I have recently updated to the most current version of Outlook (Office 365 version 1708) and the Links.Add method is now throwing the run time error 91 with the "object variable or with block variable not set" message. So, I pulled some code directly from the Microsoft Dev Ctr website and tried it, same error. The simplified code from the Microsoft website is listed below. Any assistance is very much appreciated.

Code:
Public Sub AddLink()
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myTask As Outlook.TaskItem
Dim myContact As Outlook.ContactItem
Dim myItems As Outlook.Items
Dim tempstr As String
Set myTask = Application.CreateItem(olTaskItem)
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
tempstr = InputBox("Enter the name of the contact to link to this task")
If tempstr <> "" Then
tempstr = "[Full Name] = """ & tempstr & """"
Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact.PPC'")
Set myContact = myItems.Find(tempstr)
myTask.Links.Add myContact '<<<--- this line throws error 91
myTask.Display
End If
End Sub
 
Status
Not open for further replies.
Top