Copying contents from one field to another field

Status
Not open for further replies.
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

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
 
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
 
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
>
 
Michael Bauer wrote:

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


Error 91 - object variable or With block variable not set
 
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
 
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.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
P Copying ALL calendar entries from Calender in PST file to IMAP OST file? Using Outlook 1
R VBA for copying sent email to current folder under a shared mailbox Outlook VBA and Custom Forms 17
E Copying the whole e-mail body into excel Outlook VBA and Custom Forms 0
E Copying data from e-mail attachement to EXCEL file via macro Outlook VBA and Custom Forms 38
T Copying Outlook Account Setup For Desktop App Using Outlook 5
J Outlook - 2013 - Error msg when copying folders from Online Archives to another user's mailbox Using Outlook 0
Thiago Manzano Copying E-mails to a folder on HD Using Outlook 1
Diane Poremsky Mark Sent Items as Read After Copying with a Rule Using Outlook 0
crazyboy Copying BCM database from backed up mounted image to new drive BCM (Business Contact Manager) 2
oliv- Prevent copying shared contacts Outlook VBA and Custom Forms 5
Paul Butticaz Copying Contacts from SharePoint List (connected to Outlook) to another Conacts folder Using Outlook 1
K Outlook 2010 Not responding after IMAP folder deletion or copying. Using Outlook 2
Mary B Outlook 2013: Rule for copying new email to folder & marking that copy as read Using Outlook 1
S Calendar items are not being uploaded to outlook.com after copying Using Outlook.com accounts in Outlook 1
P open reminders missing after copying outlook pst file Using Outlook 2
L Copying Emails using drag and drop Using Outlook 2
O New to Outlook 2013, dealing with copying vs. moving sent items Using Outlook 0
S Recover messages that disappeared when copying to folder Using Outlook 1
S Copying multiple messages to folders and keeping date/time detail Using Outlook 1
D Copying POP3 folders from Inbox to IMAP Inbox in Outlook 2003 Using Outlook 0
M Copying setups for mutiple users Using Outlook 2
T Location and simple copying of emails and settings, OL 2010 and Win 7 64bit. Using Outlook 3
A Copying additional contact fields when chosing "Contact from the same company" Using Outlook 5
A Copying cc email addresses to Excel - does not copy the <joe.bloggs@isp.com> Using Outlook 1
S Search Indexing (Copying Folders) Using Outlook 0
E Copying multiple folders to PST Outlook VBA and Custom Forms 2
B Copying data between atbs in a custom form Outlook VBA and Custom Forms 4
R copying a custom view from a public folder and distributing programatically Outlook VBA and Custom Forms 3
N error when copying outlook data "can not copy: the path too deep" Using Outlook 6
N Copying outlook macros between pcs Outlook VBA and Custom Forms 1
R Copying Data from Exchange to PST file Outlook VBA and Custom Forms 1
V vBA for searching a cell's contents in Outlook and retrieving the subject line Outlook VBA and Custom Forms 1
Z Outlook 365 delete reminder you can’t make change to contents of this-read only folder Using Outlook 4
B Programmatically force html send and insert clipboard contents into body Outlook VBA and Custom Forms 0
P Table AutoFit > AutoFit to Contents Outlook VBA and Custom Forms 0
A Moving archived contents in Outlook 2007 back into working folders Using Outlook 0
Diane Poremsky Paste clipboard contents using VBA Using Outlook 0
joflo copy contents from outlook to excell - please help. Using Outlook 4
S Folders not showing all contents Using Outlook 1
M Custom form on one page to post contents on second page Outlook VBA and Custom Forms 0
Z Send mail and contents of body from ms word document Using Outlook 1
R compare folder contents to e-mail attachement Using Outlook 1
S Some people can not see the contents of my shared calendar. Using Outlook 2
I How do I completely delete contents of "deleted items" to reduce pst file size Using Outlook 1
S HTML Contents of an email Jumbled in Outlook 2010 Client Using Outlook 5
M Renaming or moving contents of a field BCM (Business Contact Manager) 0
S Outlook Distribution List contents Outlook VBA and Custom Forms 1
J move contents from hundreds of emails into excel Outlook VBA and Custom Forms 4
L contents of BCM Contact groups not being displayed BCM (Business Contact Manager) 1

Similar threads

Back
Top