My question: In Outlook is there a way to link a contact to a journal entry without having to use a loop?
I am designing a custom form in Outlook 2003 using VBScript. When I open a contact, I want a button that you can click which opens a new journal entry. At the bottom of any journal entry is a text box with a "Contacts" button next to it. I want to automatically populate the text box with the name of the contact so that the journal entry is linked to the contact.
I am successfully doing this with the code below. However I am currently having to loop through all the contacts to find the contact. The user I am writing the code for has hundreds of contacts, so this loop is taking forever. I tried to replace the loop with the code colLinks.Add(Me.FullName) but this did not work because Me.FullName is not the right type of object for the Add function. So is there a way to link a contact to a journal entry without having to use a loop?
Me.Save 'this saves the contact in case it is a new contact
Const olContactItem = 2, olFolderContacts = 10
Set objContact = Application.CreateItem(4)
objContact.Type = "Note"
Set colLinks = objContact.Links
Set objNS = Application.GetNameSpace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderContacts)
Set colContacts = objFolder.Items
'THIS LOOP IS WHAT I WANT TO CHANGE
For Each myContact in colContacts
If Instr(myContact.MessageClass,"IPM.Contact") Then
If myContact.FullName = Me.FullName Then colLinks.Add(myContact)
8/22/2022 - Mon
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!