View Single Post
  #4  
Old January 13th 06, 04:32 PM posted to microsoft.public.outlook.program_vba
Bernie
external usenet poster
 
Posts: 5
Default Refering to Fields in a Contact

Doug, the user properties are accessed with the "property" called
"UserProperties". If you are doing after a specific user property then
you have something like...

Sub ShowProperty(dim sName as String )
Dim olApp As Outlook.Application
Dim objContact As Outlook.ContactItem
Dim objContacts As Outlook.MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Dim objProperty As Outlook.UserProperty

Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
Set objContact = objContacts.Items.Find("[FileAs] = """ & sName &
"""")
If Not TypeName(objContact) = "Nothing" Then
Set objProperty =
objContact.UserProperties.Find("SpouseBirthday")
If TypeName(objProperty) "Nothing" Then
MsgBox "Spouse Birthday Value is: " & objProperty.Value
End If
Else
MsgBox "The spouse birthday was not found."
End If
End Sub

The logic is that the "objContact.UserProperties" returns a collection
of all the "UserProperty". You then can "Find" or "Index" your way
through them to find the one you want. Then you have access to the
"Value" and other properties of that "UserProperty".

As a side note to this. You can scan through all the properties
associated with the contact and pick off the ones that are
"UserProperites" like this...

Dim olcf As Outlook.MAPIFolder
Dim olC As Outlook.ContactItem
Dim olIPs As Outlook.ItemProperties
Dim olIP As Outlook.ItemProperty
Dim olUserP As Outlook.UserProperty
Dim iNumContacts As Long
Dim iNumProps As Integer
..................
Set objItems = olcf.Items
iNumContacts = objItems.Count
If iNumContacts 0 Then

For I = 1 To iNumContacts
If TypeName(objItems(I)) = "ContactItem" Then
Set olC = objItems(I)
Set olIPs = olC.ItemProperties
iNumProps = olIPs.Count
If iNumProps 0 Then
' Scanning all the properties for this contact.
For j = 0 To iNumProps - 1
Set olIP = olIPs.Item(j)
If olIP.Type olOutlookInternal Then
If olIP.IsUserProperty Then
Set olUserP = olIP

'At this point we have a User Property
You can display the olUserP.Formula)
You can display the olUserP.ValidationFormula)
You can display the olUserP.ValidationText)
'
' Here is what you might have an interest in.
'
olUserP.Name - The name of the user property
olUserP.Value - The value of the user property

End If ' Not a user property.
End If ' An internal property so don't look at it.
Next j ' On to next property.
End If 'No properties for this contact - impossible.
End If ' Not a contact entry (maybe distribtion list - skip it)
Next I ' On to next entry in the contacts folder.
End If ' No contacts in folder.

Well hope that answers your question and give you some ideas of what
you can do with them.

Bernie

Ads