Reputation:
I would like to access the contacts field on an email message (Email options) in outlook. Normally this field ties an email to a contact. Since it is a freeform text field available from the options dialog box, I am trying to use it to store a "next action" for my email message. I would like to set the next action based on the subject but I can't figure out how to access thas field from the outlook.mailitem object
Thanks Jim
Upvotes: 3
Views: 2919
Reputation:
There are easier way to get Contacts list - by using Links property of oMailItem object:
For i = 1 To mailItem.Links.Count
If mailItem.Links.item(i).Type = olContact Then
Debug.Print mailItem.Links.item(i).Name
End If
Next i
Upvotes: 0
Reputation: 8868
I think this will answer it: the field is buried in a semi-generic 'Links' property, with a type of olContact. To test the following code, open a new email, put something in the contacts field, and then run the code:
Sub ShowContactsField()
Dim objApp As Outlook.Application
Dim ActiveMailItem As Inspector
Dim currLink As Link
Set objApp = CreateObject("Outlook.Application")
If TypeName(objApp.ActiveWindow) = "Inspector" Then
If objApp.ActiveInspector.CurrentItem.Class = olMail Then
For Each currLink In objApp.ActiveInspector.CurrentItem.Links
If currLink.Type = olContact Then
MsgBox currLink.Name
End If
Next
End If
End If
Set objApp = Nothing
End Sub
In general, I agree with Oliver; this probably isn't the best place to store what you're looking for, but at least it's exposed in the native form. Check the field length, I think it might be limited to 255.
Upvotes: 1
Reputation: 9459
Hmm, I also couldn't figure out how to access the Contacts field but from your description it sounds like you're not intending to use it for its intended purpose at all but rather just have the need to associate some arbitrary string data with an email item. If that is correct, I would recommend adding fields to the UserProperties
collection instead.
Upvotes: 0