Linking a contact to a journal entry

Discussion in 'Microsoft Outlook VBA Programming' started by skycity87, Jun 6, 2012.

  1. skycity87

    skycity87

    Joined:
    Jun 6, 2012
    Messages:
    2
    Likes Received:
    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
     
    skycity87, Jun 6, 2012
    #1
    1. Advertisements

  2. skycity87

    skycity87

    Joined:
    Jun 6, 2012
    Messages:
    2
    Likes Received:
    0
    Never mind, I figured it out. I can replace the loop with colLinks.Add(Item)
     
    skycity87, Jun 6, 2012
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike_B

    Public Contact logged journal entry in a Public Journal folder

    Mike_B, Aug 12, 2003, in forum: Microsoft Outlook VBA Programming
    Replies:
    1
    Views:
    686
    Sue Mosher [MVP]
    Aug 20, 2003
  2. Sue Mosher [MVP]

    Re: Setting Journal Entry Type

    Sue Mosher [MVP], Aug 26, 2003, in forum: Microsoft Outlook VBA Programming
    Replies:
    2
    Views:
    904
    publiccomputingservices
    Sep 6, 2003
  3. Charles Kenyon

    Insert text at end of journal entry

    Charles Kenyon, Feb 14, 2005, in forum: Microsoft Outlook VBA Programming
    Replies:
    13
    Views:
    363
    Guest
    Mar 29, 2005
  4. Charles Kenyon

    Setting date and time in journal entry

    Charles Kenyon, Feb 19, 2005, in forum: Microsoft Outlook VBA Programming
    Replies:
    4
    Views:
    273
    Charles Kenyon
    Feb 21, 2005
  5. David Parker

    Update of task time from journal entry

    David Parker, Oct 11, 2005, in forum: Microsoft Outlook VBA Programming
    Replies:
    4
    Views:
    369
    Michael Bauer
    Oct 13, 2005
Loading...

Share This Page