![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Outlook 2003. I am experimenting trying to access fields in my contacts. I
have the following code. I can for instance reference the contact field "FullName" using "itm.FullName" However, how do I access fields like "Home Phone"? "itm.[Home Phone]" does not work. Thanks for the help. Dim olApp As New Outlook.Application Dim olNS As Outlook.Namespace Dim ctFolder As Outlook.MAPIFolder Dim ctFolderItems As Outlook.Items Dim iterateCtItems As Integer Dim countCtItems As Integer Dim IC As Integer Dim Criteria As String Dim itm As Object On Error Resume Next Set olNS = olApp.GetNamespace("MAPI") Set ctFolder = olNS.Folders("Public Folders") Set ctFolder = ctFolder.Folders("All Public Folders") Set ctFolder = ctFolder.Folders("Good News Contacts") Set ctFolderItems = ctFolder.Items countCtItems = ctFolderItems.Count For Each itm In ctFolderItems DoEvents debug.print itm.FullName Next End Sub -- Dr. Doug Pruiett Good News Jail & Prison Ministry www.goodnewsjail.org |
Ads |
#2
|
|||
|
|||
![]()
Am Thu, 12 Jan 2006 20:25:02 -0800 schrieb Chaplain Doug:
Please see the Object Browser (F2), switch from All Libraries to Outlook and select MailItem in the left pane. In the right one you can now browse for all properties etc. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook Outlook 2003. I am experimenting trying to access fields in my contacts. I have the following code. I can for instance reference the contact field "FullName" using "itm.FullName" However, how do I access fields like "Home Phone"? "itm.[Home Phone]" does not work. Thanks for the help. Dim olApp As New Outlook.Application Dim olNS As Outlook.Namespace Dim ctFolder As Outlook.MAPIFolder Dim ctFolderItems As Outlook.Items Dim iterateCtItems As Integer Dim countCtItems As Integer Dim IC As Integer Dim Criteria As String Dim itm As Object On Error Resume Next Set olNS = olApp.GetNamespace("MAPI") Set ctFolder = olNS.Folders("Public Folders") Set ctFolder = ctFolder.Folders("All Public Folders") Set ctFolder = ctFolder.Folders("Good News Contacts") Set ctFolderItems = ctFolder.Items countCtItems = ctFolderItems.Count For Each itm In ctFolderItems DoEvents debug.print itm.FullName Next End Sub |
#3
|
|||
|
|||
![]()
Thanks Mike. I selected the object browser, Outlook, and ContactItem which
showed a list of the standard field names. But I have added some fields (user defined fields). How do I access them in my code? (e.g., itm.HomeTelephoneNumber is a standard field, I have added a field called Spouse Birthday but referencing itm.SpouseBirthday gives an error). -- Dr. Doug Pruiett Good News Jail & Prison Ministry www.goodnewsjail.org "Michael Bauer" wrote: Am Thu, 12 Jan 2006 20:25:02 -0800 schrieb Chaplain Doug: Please see the Object Browser (F2), switch from All Libraries to Outlook and select MailItem in the left pane. In the right one you can now browse for all properties etc. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook Outlook 2003. I am experimenting trying to access fields in my contacts. I have the following code. I can for instance reference the contact field "FullName" using "itm.FullName" However, how do I access fields like "Home Phone"? "itm.[Home Phone]" does not work. Thanks for the help. Dim olApp As New Outlook.Application Dim olNS As Outlook.Namespace Dim ctFolder As Outlook.MAPIFolder Dim ctFolderItems As Outlook.Items Dim iterateCtItems As Integer Dim countCtItems As Integer Dim IC As Integer Dim Criteria As String Dim itm As Object On Error Resume Next Set olNS = olApp.GetNamespace("MAPI") Set ctFolder = olNS.Folders("Public Folders") Set ctFolder = ctFolder.Folders("All Public Folders") Set ctFolder = ctFolder.Folders("Good News Contacts") Set ctFolderItems = ctFolder.Items countCtItems = ctFolderItems.Count For Each itm In ctFolderItems DoEvents debug.print itm.FullName Next End Sub |
#4
|
|||
|
|||
![]()
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 |
#5
|
|||
|
|||
![]()
THANKS BERNIE and MICHAEL. You gave me my answer. God bless!
-- Dr. Doug Pruiett Good News Jail & Prison Ministry www.goodnewsjail.org "Bernie" wrote: 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
changing info in contact fields | fowlriverjoe | Outlook - Using Contacts | 1 | February 20th 06 10:29 PM |
Some fields cannot be edited on "All Fields" tab on Contact forms | BR | Outlook - Using Contacts | 1 | February 19th 06 07:54 PM |
Dozens of custom contact fields, import into Outlook? Possible? | [email protected] | Outlook - Using Contacts | 2 | February 13th 06 05:02 PM |
Import Contact Data for certain fields only - update not replace entire contact | Pennycook | Outlook - Using Contacts | 4 | January 19th 06 06:07 AM |
How do I control printing of the fields in an Outlook Contact? | Sue Mosher [MVP-Outlook] | Outlook - Using Contacts | 0 | January 18th 06 05:06 PM |