Copying contents from one field to another field

  • Thread starter Thread starter Venger
  • Start date Start date
V

Venger

Hello -

Trying to copy contents of one field to another but NOT in a custom form.

In a regular Outlook Contacts folder, I have added 5 custom fields (by
doing Customize Current View -> Fields -> New Field...). I would like to
copy from the User Field 1, 2, 3, and 4 into those fields.

So, say one of the custom fields is Industry. I want to copy data from
User Field 1 (where data was imported to) over to the field I created
called Industry.

I have a script that looks like it should work, but it doesn't. At all.
It is below. Any and all help appreciated. Punching someone at Microsoft
for not allowing you to import into custom fields also a bonus.

Thanks!

------

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
' copy data to your custom fields
objItem.UserProperties("Industry") = objItem.User1
objItem.User1 = ""
objItem.Save
End If
Next
End If

Set objItems = Nothing
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 
What happens if you write:
objItem.UserProperties("Industry").Value = objItem.User1

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 18 Mar 2009 11:52:31 -0500 schrieb Venger:
 
Adding a UDF to the folder does not add the UDF to an individual contact
item. A UDF gets added to a given contact item when a value is entered into
the field.

Adding the following code after <If objItem.Class = olContact Then> should
resolve your problem:

On error resume next
objItem.UserProperties.Add UDFName, olType[, True/False]
***'If <True> default mode - field will also be added to Folder
UDF collection automatically if not present

On error go to <....return to whatever your regular error handling is>

......proceed with your existing code.....
objItem.UserProperties("Industry") = objItem.User1

Reason for adding the <On error resume next> is that if the property already
exists for a given contact, an error will be triggered

Karl
___________________________________________________
Karl Timmermans - The Claxton Group
ContactGenie - Importer 1.3 / DataPorter 2.0 / Exporter
"Power contact importers/exporters for MS Outlook '2000/2007"
http://www.contactgenie.com
 
Because you are not using a custom form, you must add the Industry field to
the item before you can set its value. Take a look at the UserProperties.Add
method.
 
Karl said:
Adding a UDF to the folder does not add the UDF to an individual contact
item. A UDF gets added to a given contact item when a value is entered into
the field.

Adding the following code after <If objItem.Class = olContact Then> should
resolve your problem:

On error resume next
objItem.UserProperties.Add UDFName, olType[, True/False]
***'If <True> default mode - field will also be added to Folder
UDF collection automatically if not present

On error go to <....return to whatever your regular error handling is>

.....proceed with your existing code.....
objItem.UserProperties("Industry") = objItem.User1

Reason for adding the <On error resume next> is that if the property already
exists for a given contact, an error will be triggered

Yes, I see the problem now - I edited my script and now that the
contacts have the property added, the field value reassignments work
perfectly.

Thanks to everyone for your help!

Venger
 
Sue said:
Because you are not using a custom form, you must add the Industry field to
the item before you can set its value. Take a look at the UserProperties.Add
method.

Yes, between your original script (I think your script is the base I
worked from) and Karl's adjustments, I got it working.

Greatly appreciate your help, and for having made the scripts available
in the first place.
 
Back
Top