[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

656 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