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
Solved

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

Posted on 2014-03-28
1
615 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
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
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…
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…

792 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