Solved

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

Posted on 2014-03-28
1
620 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
bvallanc earned 0 total points
ID: 39962854
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

763 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