Solved

Outlook 2007 VBA Syntax To Change The Value Of  A Contact Property

Posted on 2014-03-28
1
604 Views
Last Modified: 2014-03-28
I have been struggling for three hours trying to find the syntax to change the value of a user-defirned field on a custom contact form.  I am able to read the value of the field with the following syntax:

Dim objNS As Outlook.NameSpace
Dim objContactsFldr As Outlook.Folder
Dim objContactItems As Outlook.Items
Dim objContact As Outlook.ContactItem

Set objNS = Application.GetNamespace("MAPI")
Set objContactsFldr = objNS.GetDefaultFolder(olFolderContacts)
Set objContactItems = objContactsFldr.Items.Restrict("[MessageClass = 'IPM.Contact.LeadGen1_1'")

'This reads perfectly
Debug.Print objContact.UserProperties.Find("CallTask1").Value

'But this fails with Error 242 - Object required ...
Set objContact.UserProperties.Find("CallTask1").Value = True

Open in new window

I can't figure out what I'm doing wrong.  I can't find anything by Googling.  Is this a black art or something?

Thanks,

Bill Vallance
0
Comment
Question by:bvallanc
1 Comment
 

Accepted Solution

by:
bvallanc earned 0 total points
Comment Utility
I figured it out after 3 MORE hours:

1. Dim a Property Object
2. Set the Property Object = ContactObject.UserProperties.Item("FieldName")
3. Change the value of the Property Object (the field)
4. SAVE THE FORM OR ELSE THE CHANGE TO THE FIELD WON'T BE SAVED (this cost me 2 hours of research)

Here's the code (add it to the code in my previous post):

Dim objProperty As Outlook.UserProperty
 Set objProperty = objContact.UserProperties.Item("CallTask1")
 objProperty.Value = False   'this is for a checkbox control
 objContact.Close olSave

Open in new window

You CANNOT combine Line 2 and 3!  You have to set the objProperty THEN change its Value.  Line 4 is the code to Close and Save the objContact object that has been loaded into memory, but not made visible.

Hope This Helps Someone Down The Road,

Bill Vallance
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now