PC Review


Reply
Thread Tools Rate Thread

Copy field value in Contacts

 
 
=?Utf-8?B?VHJvaXMgSmF5?=
Guest
Posts: n/a
 
      7th Jul 2005
I need to copy the value of the Nickname field to the Pager field of each
contact in the Contacts-folder.

IOW: loop through the contacts-collection and copy any value in the Nickname
field to the Pager field of that contact, then empty the Nickname field.

I'm familiar with VBA; just don't know the exact syntax of the Outlook
object model.

Thanks in advance.

Jay
 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      7th Jul 2005
See http://www.outlookcode.com/d/code/convertfields.htm for a code sample that should be useful. When in doubt about the exact property names, check the object browser: Press ALt+F11 to open the VBA environment in Outlook, then press F2. Switch from <All Libraries> to Outlook to browse all Outlook objects and their properties, methods, and events. Select any object or member, then press F1 to see its Help topic.


--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Trois Jay" <(E-Mail Removed)> wrote in message news:130D7ABF-28FD-40E3-B588-(E-Mail Removed)...
>I need to copy the value of the Nickname field to the Pager field of each
> contact in the Contacts-folder.
>
> IOW: loop through the contacts-collection and copy any value in the Nickname
> field to the Pager field of that contact, then empty the Nickname field.
>
> I'm familiar with VBA; just don't know the exact syntax of the Outlook
> object model.
>
> Thanks in advance.
>
> Jay

 
Reply With Quote
 
Michael Bauer
Guest
Posts: n/a
 
      7th Jul 2005
Jay, you can see the syntax in the Object Browser (F2). Interesting for
you: ContactItem, Nickname, PagerNumber, Save.

Trois Jay wrote:
> I need to copy the value of the Nickname field to the Pager field of
> each contact in the Contacts-folder.
>
> IOW: loop through the contacts-collection and copy any value in the
> Nickname field to the Pager field of that contact, then empty the
> Nickname field.
>
> I'm familiar with VBA; just don't know the exact syntax of the Outlook
> object model.
>
> Thanks in advance.
>
> Jay


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook


 
Reply With Quote
 
=?Utf-8?B?VHJvaXMgSmF5?=
Guest
Posts: n/a
 
      7th Jul 2005
Thank you Michael and Sue,

with some c & p and F1 + F2, I managed to make it work.

Just in case anyone else needs it:

================================================

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

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(10)

lngcounter = 0

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
If IsNull(objItem.NickName) = True Or objItem.NickName = "" Then

Else
objItem.PagerNumber = objItem.NickName
objItem.NickName = ""
objItem.Save
lngcounter = lngcounter + 1
End If
End If
Next
End If

MsgBox "'" & lngcounter & "' nicknames copied to pager-field."

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

================================================

"Trois Jay" wrote:

> I need to copy the value of the Nickname field to the Pager field of each
> contact in the Contacts-folder.
>
> IOW: loop through the contacts-collection and copy any value in the Nickname
> field to the Pager field of that contact, then empty the Nickname field.
>
> I'm familiar with VBA; just don't know the exact syntax of the Outlook
> object model.
>
> Thanks in advance.
>
> Jay

 
Reply With Quote
 
Michael Bauer
Guest
Posts: n/a
 
      8th Jul 2005
Thanks for the sample, Jay.


> Set objApp = CreateObject("Outlook.Application")


From within OL you shouldn´t call this. In OL 2003 you could run into
security prompts and it seems that this line could cause that VBA will
be disabled.

> If IsNull(objItem.NickName) = True Or objItem.NickName = ""


Because NickName is a String type it will never be Null. So it´s enough
to test for NickName="" only. In your case you could write this (the
Else case isn´t necessary):

If objItem.NickName <> "" Then
....
Endif

Or this (faster):

If Len(objItem.NickName)=0 then
....
Endif


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook



Trois Jay wrote:
> Thank you Michael and Sue,
>
> with some c & p and F1 + F2, I managed to make it work.
>
> Just in case anyone else needs it:
>
> ================================================
>
> Sub ConvertFields()
> Dim objApp As Application
> Dim objNS As NameSpace
> Dim objFolder As MAPIFolder
> Dim objItems As Items
> Dim objItem As Object
> Dim lngcounter As Long
>
> Set objApp = CreateObject("Outlook.Application")
> Set objNS = objApp.GetNamespace("MAPI")
> Set objFolder = objNS.GetDefaultFolder(10)
>
> lngcounter = 0
>
> 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
> If IsNull(objItem.NickName) = True Or objItem.NickName = ""
> Then
>
> Else
> objItem.PagerNumber = objItem.NickName
> objItem.NickName = ""
> objItem.Save
> lngcounter = lngcounter + 1
> End If
> End If
> Next
> End If
>
> MsgBox "'" & lngcounter & "' nicknames copied to pager-field."
>
> Set objItems = Nothing
> Set objItem = Nothing
> Set objFolder = Nothing
> Set objNS = Nothing
> Set objApp = Nothing
> End Sub
>
> ================================================
>
> "Trois Jay" wrote:
>
>> I need to copy the value of the Nickname field to the Pager field of
>> each contact in the Contacts-folder.
>>
>> IOW: loop through the contacts-collection and copy any value in the
>> Nickname field to the Pager field of that contact, then empty the
>> Nickname field.
>>
>> I'm familiar with VBA; just don't know the exact syntax of the
>> Outlook object model.
>>
>> Thanks in advance.
>>
>> Jay


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fastest Way to Copy Business Manager Contacts to Outlook Contacts allanc Microsoft Outlook Discussion 0 7th Jun 2007 05:33 PM
Copy contents of a field does not copy complete field =?Utf-8?B?U2FuZHk=?= Microsoft Access Macros 3 24th Nov 2006 03:16 PM
Copy contents of a field does not copy complete field =?Utf-8?B?U2FuZHk=?= Microsoft Access VBA Modules 2 24th Nov 2006 02:39 PM
Copy contents of a field does not copy complete field =?Utf-8?B?U2FuZHk=?= Microsoft Access VBA Modules 0 23rd Nov 2006 08:37 PM
Cannot copy contacts from Outlook 2000 mailbox to Public Folder Contacts Ken Hack Microsoft Outlook Contacts 0 15th Sep 2004 04:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:22 AM.