?
Solved

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

Posted on 2014-03-28
1
Medium Priority
?
625 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Changing a few Outlook Options can help keep you organized!
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

762 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