Linking a contact to a journal entry


Joined
Jun 6, 2012
Messages
2
Reaction score
0
Hello,

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?

Thank you,

Joey


Sub CommandButton2_Click()
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)
End If
Next

objContact.Display


End Sub
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top