Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Problem with setting Outlook item userproperties (http://www.outlookbanter.com/outlook-vba/11482-problem-setting-outlook-item-userproperties.html)

KeithXP April 13th 06 04:08 PM

Problem with setting Outlook item userproperties
 
I am trying to use the following code (downloaded from OutlookCode.com and
modified to suit my requirements) to move information from the built in User
fields to custom property fields. I have only altered the name of the form
to be used and the names of the custom fields.

On running the code I get:
Run-time error '-13179289555 (b1720005)':
Method 'UserProperties' of object 'ContactItem' failed

I am pretty inexperienced in VBA in general so haven't a clue what the
problem is. I did try the syntax

objItem.UserProperties("Hotels").value = objItem.User1

but received a similar error.

Any ideas?

thanks

Keith

----------------------------------------------------------------------------------

Sub ConvertFields()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItems As Items
Dim objItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set objItems = objFolder.Items
For Each objItem In objItems
' make sure you have a Contact item
If objItem.Class = olContact Then
' convert to your published custom form
objItem.MessageClass = "IPM.Contact.PRList"
' copy data to your custom fields
objItem.UserProperties("Hotels") = objItem.User1
objItem.UserProperties("Residential") = objItem.User2
objItem.UserProperties("Prop. Dev.") = objItem.User3
objItem.UserProperties("Gardens") = objItem.User4
objItem.UserProperties("Projects") = objItem.Department
'comment out following lines until code is working
'objItem.User1 = ""
'objItem.User2 = ""
'objItem.User3 = ""
'objItem.User4 = ""
objItem.Save
End If
Next
End If

Set objItems = Nothing
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing

End Sub




Ken Slovak - [MVP - Outlook] April 13th 06 04:18 PM

Problem with setting Outlook item userproperties
 
If those user properties don't already exist you first must add them to the
UserProperties collection:

Dim oProp As Outlook.UserProperty
Dim colProps As Outlook.UserProperties

Set colProps = objItem.UserProperties
Set oProp = colProps.Add("Hotels", olText, True)
oProp.Value = objItem.User1

etc.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"KeithXP" wrote in message
.. .
I am trying to use the following code (downloaded from OutlookCode.com and
modified to suit my requirements) to move information from the built in
User
fields to custom property fields. I have only altered the name of the form
to be used and the names of the custom fields.

On running the code I get:
Run-time error '-13179289555 (b1720005)':
Method 'UserProperties' of object 'ContactItem' failed

I am pretty inexperienced in VBA in general so haven't a clue what the
problem is. I did try the syntax

objItem.UserProperties("Hotels").value = objItem.User1

but received a similar error.

Any ideas?

thanks

Keith

----------------------------------------------------------------------------------

Sub ConvertFields()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItems As Items
Dim objItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set objItems = objFolder.Items
For Each objItem In objItems
' make sure you have a Contact item
If objItem.Class = olContact Then
' convert to your published custom form
objItem.MessageClass = "IPM.Contact.PRList"
' copy data to your custom fields
objItem.UserProperties("Hotels") = objItem.User1
objItem.UserProperties("Residential") = objItem.User2
objItem.UserProperties("Prop. Dev.") = objItem.User3
objItem.UserProperties("Gardens") = objItem.User4
objItem.UserProperties("Projects") = objItem.Department
'comment out following lines until code is working
'objItem.User1 = ""
'objItem.User2 = ""
'objItem.User3 = ""
'objItem.User4 = ""
objItem.Save
End If
Next
End If

Set objItems = Nothing
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing

End Sub





KeithXP April 13th 06 05:20 PM

Problem with setting Outlook item userproperties
 
Thanks for this, but as I understand it, the user properties do exist
already.

If I open any item in the folder, go to the 'All Fields' tab, my
'userproperties' are all listed under 'User-defined fields in this item'.
The are also listed under 'User-defined fields in folder'.

Keith


"Ken Slovak - [MVP - Outlook]" wrote in message
...
If those user properties don't already exist you first must add them to
the UserProperties collection:

Dim oProp As Outlook.UserProperty
Dim colProps As Outlook.UserProperties

Set colProps = objItem.UserProperties
Set oProp = colProps.Add("Hotels", olText, True)
oProp.Value = objItem.User1

etc.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"KeithXP" wrote in message
.. .
I am trying to use the following code (downloaded from OutlookCode.com and
modified to suit my requirements) to move information from the built in
User
fields to custom property fields. I have only altered the name of the
form
to be used and the names of the custom fields.

On running the code I get:
Run-time error '-13179289555 (b1720005)':
Method 'UserProperties' of object 'ContactItem' failed

I am pretty inexperienced in VBA in general so haven't a clue what the
problem is. I did try the syntax

objItem.UserProperties("Hotels").value = objItem.User1

but received a similar error.

Any ideas?

thanks

Keith

----------------------------------------------------------------------------------

Sub ConvertFields()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItems As Items
Dim objItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set objItems = objFolder.Items
For Each objItem In objItems
' make sure you have a Contact item
If objItem.Class = olContact Then
' convert to your published custom form
objItem.MessageClass = "IPM.Contact.PRList"
' copy data to your custom fields
objItem.UserProperties("Hotels") = objItem.User1
objItem.UserProperties("Residential") = objItem.User2
objItem.UserProperties("Prop. Dev.") = objItem.User3
objItem.UserProperties("Gardens") = objItem.User4
objItem.UserProperties("Projects") = objItem.Department
'comment out following lines until code is working
'objItem.User1 = ""
'objItem.User2 = ""
'objItem.User3 = ""
'objItem.User4 = ""
objItem.Save
End If
Next
End If

Set objItems = Nothing
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing

End Sub







KeithXP April 13th 06 05:31 PM

Problem with setting Outlook item userproperties
 
Ken -
Could this be a data type problem? I imported the contacts from Excel and
the information in the User1-4 fields is logical (stored as Yes/No).

I have created the new userproperty fields as Yes/No type, format Yes/No.
Could there be a problem transferring the data from the User1 field (string)
to the "Hotels" field (Yes/No)?

If so, any idea how to get around it...

thanks





"Ken Slovak - [MVP - Outlook]" wrote in message
...
If those user properties don't already exist you first must add them to
the UserProperties collection:

Dim oProp As Outlook.UserProperty
Dim colProps As Outlook.UserProperties

Set colProps = objItem.UserProperties
Set oProp = colProps.Add("Hotels", olText, True)
oProp.Value = objItem.User1

etc.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"KeithXP" wrote in message
.. .
I am trying to use the following code (downloaded from OutlookCode.com and
modified to suit my requirements) to move information from the built in
User
fields to custom property fields. I have only altered the name of the
form
to be used and the names of the custom fields.

On running the code I get:
Run-time error '-13179289555 (b1720005)':
Method 'UserProperties' of object 'ContactItem' failed

I am pretty inexperienced in VBA in general so haven't a clue what the
problem is. I did try the syntax

objItem.UserProperties("Hotels").value = objItem.User1

but received a similar error.

Any ideas?

thanks

Keith

----------------------------------------------------------------------------------

Sub ConvertFields()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItems As Items
Dim objItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set objItems = objFolder.Items
For Each objItem In objItems
' make sure you have a Contact item
If objItem.Class = olContact Then
' convert to your published custom form
objItem.MessageClass = "IPM.Contact.PRList"
' copy data to your custom fields
objItem.UserProperties("Hotels") = objItem.User1
objItem.UserProperties("Residential") = objItem.User2
objItem.UserProperties("Prop. Dev.") = objItem.User3
objItem.UserProperties("Gardens") = objItem.User4
objItem.UserProperties("Projects") = objItem.Department
'comment out following lines until code is working
'objItem.User1 = ""
'objItem.User2 = ""
'objItem.User3 = ""
'objItem.User4 = ""
objItem.Save
End If
Next
End If

Set objItems = Nothing
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing

End Sub







Ken Slovak - [MVP - Outlook] April 14th 06 03:01 PM

Problem with setting Outlook item userproperties
 
If strValue = "Yes" Then
blnValue = True
Else
blnValue = False
End If

oProp.Value = blnValue

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"KeithXP" wrote in message
.. .
Ken -
Could this be a data type problem? I imported the contacts from Excel and
the information in the User1-4 fields is logical (stored as Yes/No).

I have created the new userproperty fields as Yes/No type, format Yes/No.
Could there be a problem transferring the data from the User1 field
(string) to the "Hotels" field (Yes/No)?

If so, any idea how to get around it...

thanks




All times are GMT +1. The time now is 11:52 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com