Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I access custom fields in Outlook? 1

Status
Not open for further replies.

RockSolid

Programmer
Oct 13, 2002
7
NZ
I am currently working on a project where I am using VB.NET to read records from a database and write them into a custom Contact form in Outlook. I am able to put information into the standard fields, but have not been able to connect to the custom fields in the form to write information in them. Does anyone have any ideas?
 
to get the value

contact.UserProperties.Find("Custom Field1").Value

and to set the value

contact.UserProperties.Find("Custom Field1").Value ="TEST"

(a Star will be good if it helps)
 
Thanks for your help. However, when I tried it, I got an error message "Object reference not set to an instance of an object", which pointed to the UserProperties line, and commenting it out, the code works fine. The following is part of my code.

Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objContactFolder As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem

objOutlook = CreateObject("Outlook.Application")
objNamespace = objOutlook.GetNamespace("MAPI")
objContactFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)

Do Until datRead.Read = False
objContact = objOutlook.CreateItem(Outlook.OlItemType.olContactItem)
objContact.MessageClass = "IPM.Contact.MaM"
objContact.Title = datRead("Title")
objContact.LastName = datRead("Surname")
objContact.FirstName = datRead("FirstName")

objContact.UserProperties.Find("Salutation").Value = datRead("Salutation")

objContact.Save()
Loop

I also tried the line:
objOutlook = New Outlook.Application()
instead of the line:
objOutlook = CreateObject("Outlook.Application")
but I got the same error message. This was also the result when I tried putting the New in the declaration.

Can you see what I'm missing?
 
thank u for the star..

Try this code..

Do Until datRead.Read = False
objContact = objContactFolder.Add("IPM.Contact.MaM")
objContact.Title = datRead("Title")
objContact.LastName = datRead("Surname")
objContact.FirstName = datRead("FirstName")

objContact.UserProperties("Salutation").Value = datRead("Salutation")

objContact.Save()
Loop

(one more star if it helps)
 
Thanks, you're an absolute legend, and truly deserve another star!!

Initially, your suggestion didn't work, but it pointed me in the right direction. After I made the following changes, it worked like a charm.

objContact = objContactFolder.Items.Add("IPM.Contact.MaM")
objContact.UserProperties.Find("Salutation").Value = datRead("Salutation")

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top