Copying contents from one field to another field

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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
What happens if you write:

objItem.UserProperties("Industry").Value = objItem.User1

Best regards

Michael Bauer

Am Wed, 18 Mar 2009 11:52:31 -0500 schrieb 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
 

Karl Timmermans

Senior Member
Outlook version
Outlook 2013 32 bit
Email Account
POP3
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

_____________

ContactGenie - Importer 1.3 / DataPorter 2.0 / Exporter

"Power contact importers/exporters for MS Outlook '2000/2007"

"Venger" <venger@mail.com> wrote in message

news:jF9wl.2268$im1.1883@nlpi061.nbdc.sbc.com...

> 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
 
S

Sue Mosher

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.

Sue Mosher

"Venger" wrote:



> 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
>
 
V

Venger

Michael Bauer wrote:

> What happens if you write:
> objItem.UserProperties("Industry").Value = objItem.User1


Error 91 - object variable or With block variable not set
 
V

Venger

Karl Timmermans wrote:
> 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
 
V

Venger

Sue Mosher [MVP-Outlook] wrote:
> 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.
 

Top