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
 

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.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Copy folders without copying contents of folders? Using Outlook 4
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 New Slipstick.com Articles 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
I copying messages from inbox to folder outside outlook Using Outlook 2
C Copying an email. Using Outlook 1
B Moving or copying a Hotmail Folder to an external Hard Disk?____ Using Outlook 2
F copying outlook Using Outlook 3
T Copying contacts Using Outlook 3
I Copying mailboxes from Exchange 2003 to Exchange 2010 Exchange Server Administration 3
1 Error message when copying contacts from one group to another Using Outlook 2
R copying or cutting an appointment to paste it to a different date Using Outlook 1
O Copying Outlook Categories to the attachment (MS word) body in bulk. Is this possible? Using Outlook 7
J Random copying of emails in inbox and calendar appointments deleted Using Outlook 1
S How to retain "Date Sent" and "Date Received" data when copying email messages from Outlook to an Ex Using Outlook 2
A Copying Outlook to Windows 7 Using Outlook 1
A Copying Outlook t5o Windows 7 Using Outlook 1
J Outlook won't allow hyperlink in email to work, but copying & posting hyperlink in browser works OK. Using Outlook 1
S Copying suggested outlook names from Outlook 2003 to 2010. Using Outlook 1
T Adding or copying a duplicate contact does not get detected and stopped Using Outlook 1
P copying calendar from desktop computer for use on laptop computer Using Outlook 1
Q Copying Outlook 2003/XP contact list to Outlook 2007/Windows 7 Using Outlook 25
G Copying Outlook Contact File Onto Disk Using Outlook 1
L Copying Outlook.pst file to Outlook 2010 Using Outlook 1
D Importing or Copying Signature Files from 2007 to 2010 Using Outlook 1
B Copying database from my desktop to laptop and vice versa Using Outlook 1
A copying contact to new computer Using Outlook 0
D Hyperlink formatting getting messed up copying and pasting from Word 07 into Outlook 07. Using Outlook 1
R Copying an existing distribution list into a new distribution list in my contacts. Using Outlook 1
Similar threads


















































Top