troubleshooting Question

Custom Form in Outlook 2003

Avatar of skycity872
skycity872 asked on
OutlookVB Script
5 Comments1 Solution631 ViewsLast Modified:
My question:  In Outlook is there a way to link a contact to a journal entry without having to use a loop?

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
ASKER CERTIFIED SOLUTION
Robberbaron (robr)

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros