Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I access an user-defined field with code? (xp)

    I would like to change the value of an user-defined field in Outlook 2002 from an other application using VBA.
    Any help will be appreciated,
    Marcel.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can I access an user-defined field with code? (xp)

    I don't know how familiar you are with using Automation to control one application in VBA from another application.
    If not, do a search or ask. You need to set a reference to the Microsoft Outlook x.x Object Model in the controlling application.

    Outlook items have a UserProperties collection.

    You can use code like the following:

    Dim olContact As Outlook.ContactItem
    Set olItem = ...
    olContact.UserProperties("MyProperty") = "John"

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can I access an user-defined field with code? (xp)

    Thank you for your help. I was forgetting the quote. I have tried the following code and it works well if I have already a value in the P field. If the P field is nothing the code doesn't update the field value. Any suggestion?
    Thanks for your help.
    Marcel.

    Sub Access_UserFields()

    Dim fdrTasks As Outlook.MAPIFolder
    Dim itmTask As Outlook.TaskItem

    Set fdrTasks = Application.GetNamespace("MAPI").GetDefaultFolder( olFolderTasks)

    For i = 1 To fdrTasks.Items.Count
    Set itmTask = fdrTasks.Items.Item(i)
    itmTask.UserProperties("P") = "1"
    itmTask.Save
    Next i
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can I access an user-defined field with code? (xp)

    Has the user property been created?

    Dim prp As UserProperty
    Set prp = itmTask.UserProperties.Add("P", olText)

    If a property hasn't been created, you can't assign a value to it.

  5. #5
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How can I access an user-defined field with code? (xp)

    The user property already existed in my task folder but some tasks don't have a value in this field.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How can I access an user-defined field with code? (xp)

    Apparently, adding a custom field to the Tasks folder doesn't add the field to tasks automatically. If the field hasn't been set before, you have to create it:

    For i = 1 To fdrTasks.Items.Count
    Set itmTask = fdrTasks.Items.Item(i)
    If itmTask.UserProperties("P") Is Nothing Then
    itmTask.UserProperties.Add "P", olText, False
    End If
    itmTask.UserProperties("P") = "1"
    itmTask.Save
    Next i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •