Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_cdo thread: How to access UserField1 of Outlook Contacts


Message #1 by "Dante Tang" <dan.tang@s...> on Mon, 22 Oct 2001 07:19:46
I am trying to access the UserFields of Outlook contacts by using CDO 

1.2.1 in ASP. I have 



established a MAPI Session as shown below:



Set CdoSession = Server.CreateObject("MAPI.Session")

strProfileInfo = ServerName & vbLf & LogonName

CdoSession.Logon , , False, False, , , strProfileInfo



According to my observation, Contacts is one of the default folders in 

Outlook. The 



following code is used to get a reference to the Messages collection of 

Contacts folder.



Set CdoFolder = CdoSession.GetDefaultFolder(cdoDefaultFolderContacts)

Set CdoMessages = CdoFolder.Messages



There are many messages in the CdoMessages. And there is a field 

collection called Fields of 



each message. However, I got an error when I try to get the value of 

UserField1 of a 



message.



Response.Write(CdoMessage.Fields("0420060000000000C000000000000046" 

& "0x804F").Value)



I have also tried this statement:



Response.Write(CdoMessages.Item("0420060000000000C000000000000046" 

& "0x804F"))



But it also does not work... does anyone know how to access the field 

UserField1 of a 



Contacts? I really need your help. Thanks very much in advance.



Dante
Message #2 by "Siegfried Weber" <sweber@c...> on Mon, 22 Oct 2001 11:09:37 +0200
The syntax used to retrieve this field is slightly wrong. Try:



Response.Write(CdoMessage.Fields("{0420060000000000C000000000000046}0x80

4F").Value)



And make sure you add an "On Error Resume Next" before. Otherwise it

will error out on each contact item where this field is empty.



<Siegfried />



> -----Original Message-----

> From: Dante Tang [mailto:dan.tang@s...]

> Sent: Monday, October 22, 2001 9:20 AM

> To: ASP CDO

> Subject: [asp_cdo] How to access UserField1 of Outlook Contacts

>

> I am trying to access the UserFields of Outlook contacts by using CDO

> 1.2.1 in ASP. I have established a MAPI Session as shown below:

>

> Set CdoSession = Server.CreateObject("MAPI.Session")

> strProfileInfo = ServerName & vbLf & LogonName

> CdoSession.Logon , , False, False, , , strProfileInfo

>

> According to my observation, Contacts is one of the default folders in

> Outlook. The following code is used to get a reference to the Messages 

> collection of Contacts folder.

>

> Set CdoFolder = CdoSession.GetDefaultFolder(cdoDefaultFolderContacts)

> Set CdoMessages = CdoFolder.Messages

>

> There are many messages in the CdoMessages. And there is a field

> collection called Fields of each message. However, I got an error when I 

> try to get the value of UserField1 of a message.

>

> Response.Write(CdoMessage.Fields("0420060000000000C000000000000046"

> & "0x804F").Value)

>

> I have also tried this statement:

>

> Response.Write(CdoMessages.Item("0420060000000000C000000000000046"

> & "0x804F"))

>

> But it also does not work... does anyone know how to access the field

> UserField1 of a Contacts? I really need your help. Thanks very much in 

> advance.

>

> Dante
Message #3 by "Dante Tang" <dante.tang@s...> on Tue, 23 Oct 2001 04:37:11
Thanks Siegfried~ I can read the value of UserField1 after changing to 

your syntax (Um, can you tell me where did you find this syntax?)



And I have written a procedure to add a new contact. However, I cannot add 

the UserField1 value. But when I change the ProgTag to the Job Title's 

one. It works perfectly... Do you know what is the problem?



Below is my code, please have a look and million thanks in advance.







Sub AddContact

  Set CdoFolder = CdoSession.GetDefaultFolder(cdoDefaultFolderContacts)    

  Set CdoMessages = CdoFolder.Messages

  Set CdoMessage = CdoMessages.Add

  CdoMessage.Subject = "Jane Doe"

  CdoMessage.Type = "IPM.Contact"

  

'  ProgTag = "&H3A17001F"  // Job Title

'  ProgTag = "{0420060000000000C000000000000046}0x804F"  // UserField1

  

  Set CdoFields = CdoMessage.Fields

  

  On Error Resume Next

  Set CdoField = CdoFields("{0420060000000000C000000000000046}0x804F")

  

  If Err.Number = 0 Then

    ' The Field object was found. Now set its value.

    CdoField.Value = "alert"

    Response.Write("Field was found")

  ElseIf Err = -2147221233 Then

    ' The Field object was not found. Add it and set its value.

    Set CdoField = CdoFields.Add("{0420060000000000C000000000000046}

0x804F", "alert")

    

    Response.Write("Field not found")

  Else

    ' Else an error occurred.    

    Response.Write(Err.Number & " " & Err.Description)

  End If 

  

  CdoMessage.Update

  Response.Write("<P>Created a new contact<BR>")

  

  CdoField = Nothing

  CdoFields = Nothing  

End Sub









> The syntax used to retrieve this field is slightly wrong. Try:

> 

> Response.Write(CdoMessage.Fields("{0420060000000000C000000000000046}0x80

> 4F").Value)

> 

> And make sure you add an "On Error Resume Next" before. Otherwise it

> will error out on each contact item where this field is empty.

> 

> <Siegfried />

> 

> > -----Original Message-----

> > From: Dante Tang [mailto:dan.tang@s...]

> > Sent: Monday, October 22, 2001 9:20 AM

> > To: ASP CDO

> > Subject: [asp_cdo] How to access UserField1 of Outlook Contacts

> >

> > I am trying to access the UserFields of Outlook contacts by using CDO

> > 1.2.1 in ASP. I have established a MAPI Session as shown below:

> >

> > Set CdoSession = Server.CreateObject("MAPI.Session")

> > strProfileInfo = ServerName & vbLf & LogonName

> > CdoSession.Logon , , False, False, , , strProfileInfo

> >

> > According to my observation, Contacts is one of the default folders in

> > Outlook. The following code is used to get a reference to the Messages 

> > collection of Contacts folder.

> >

> > Set CdoFolder = CdoSession.GetDefaultFolder(cdoDefaultFolderContacts)

> > Set CdoMessages = CdoFolder.Messages

> >

> > There are many messages in the CdoMessages. And there is a field

> > collection called Fields of each message. However, I got an error when 

I 

> > try to get the value of UserField1 of a message.

> >

> > Response.Write(CdoMessage.Fields("0420060000000000C000000000000046"

> > & "0x804F").Value)

> >

> > I have also tried this statement:

> >

> > Response.Write(CdoMessages.Item("0420060000000000C000000000000046"

> > & "0x804F"))

> >

> > But it also does not work... does anyone know how to access the field

> > UserField1 of a Contacts? I really need your help. Thanks very much in 

> > advance.

> >

> > Dante
Message #4 by "Siegfried Weber" <sweber@c...> on Tue, 23 Oct 2001 08:12:10 +0200
Inline...



<Siegfried />



> -----Original Message-----

> Thanks Siegfried~ I can read the value of UserField1 after changing to

> your syntax (Um, can you tell me where did you find this syntax?)



http://www.cdolive.com/cdo10.htm



> And I have written a procedure to add a new contact. However, I cannot

add

> the UserField1 value. But when I change the ProgTag to the Job Title's

> one. It works perfectly... Do you know what is the problem?



For Userfield1, try:



CdoFields.Add "0x804F", vbString, "HR Travelrequest", _

                                   "0420060000000000C000000000000046"



For your custom field, try:



CdoFields.Add "PersonRole", vbString, "HR Lead", _

                                   "2903020000000000C000000000000046"



More info can be found at the page mentioned above.




  Return to Index