Write data into ContactItem field

T

TS Lim

After finding a contact item, is it possible to write data into another field
of the item ?
In the example below, after finding the item with the CustomerID field. It
try to write data into the Spouse field. Is it the right way to do it ? It
not, kindly advsie a way where I can write data into the fields of item
selected.

Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Folder
Dim myItem As Outlook.ContactItem

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[CustomerID] = ""ID0000001""")

myItem.Spouse = "Mrs ID000001"

myItem.Save


Your advise is appreciated.

Thank you.

TS Lim
 
D

Dmitry Streblechenko

Looks fine to me. Does it work for you?
You might want to check that myItem is not Nothing first.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
T

TS Lim

Dear Dmitry,

I tried to run it, but it does not work.

TS Lim


Dmitry Streblechenko said:
Looks fine to me. Does it work for you?
You might want to check that myItem is not Nothing first.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
TS Lim said:
After finding a contact item, is it possible to write data into another
field
of the item ?
In the example below, after finding the item with the CustomerID field. It
try to write data into the Spouse field. Is it the right way to do it ?
It
not, kindly advsie a way where I can write data into the fields of item
selected.

Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Folder
Dim myItem As Outlook.ContactItem

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[CustomerID] = ""ID0000001""")

myItem.Spouse = "Mrs ID000001"

myItem.Save


Your advise is appreciated.

Thank you.

TS Lim
 
T

TS Lim

After finding the item, I can read data of fields of the item. But to write
data, it still does not work. Any advise ?

TS Lim


Sue Mosher said:
Yes, that's it exactly.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers




TS Lim said:
After finding a contact item, is it possible to write data into another field
of the item ?
In the example below, after finding the item with the CustomerID field. It
try to write data into the Spouse field. Is it the right way to do it ? It
not, kindly advsie a way where I can write data into the fields of item
selected.

Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Folder
Dim myItem As Outlook.ContactItem

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[CustomerID] = ""ID0000001""")

myItem.Spouse = "Mrs ID000001"

myItem.Save


Your advise is appreciated.

Thank you.

TS Lim
 
S

Sue Mosher [MVP-Outlook]

What specifically doesn't work? Error messages? Other symptoms? Does myItem
return the correct object?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers




TS Lim said:
After finding the item, I can read data of fields of the item. But to write
data, it still does not work. Any advise ?

TS Lim


Sue Mosher said:
Yes, that's it exactly.

TS Lim said:
After finding a contact item, is it possible to write data into another field
of the item ?
In the example below, after finding the item with the CustomerID field. It
try to write data into the Spouse field. Is it the right way to do it ? It
not, kindly advsie a way where I can write data into the fields of item
selected.

Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Folder
Dim myItem As Outlook.ContactItem

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[CustomerID] = ""ID0000001""")

myItem.Spouse = "Mrs ID000001"

myItem.Save


Your advise is appreciated.

Thank you.

TS Lim
 
T

TS Lim

When I run the sub procedure, no error message was prompted, and when
checking with my outlook folder, the Spouse field was not updated.

I try to check by adding 2 msgbox as show below. When the procedure is run,
Test 1 message box prompted, but Test 2 message box does not prompt. Looks
like the procedure stop running at the line 'myItem.Spouse = "Mrs ID000001"'

Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Folder
Dim myItem As Outlook.ContactItem

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[CustomerID] = ""ID0000001""")

Msgbox "Test 1 on whether procedure run until here"

myItem.Spouse = "Mrs ID000001"

Msgbox "Test 2 on wheterh procedure run until here"

myItem.Save



Sue Mosher said:
What specifically doesn't work? Error messages? Other symptoms? Does myItem
return the correct object?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers




TS Lim said:
After finding the item, I can read data of fields of the item. But to write
data, it still does not work. Any advise ?

TS Lim


Sue Mosher said:
Yes, that's it exactly.

:

After finding a contact item, is it possible to write data into another field
of the item ?
In the example below, after finding the item with the CustomerID field. It
try to write data into the Spouse field. Is it the right way to do it ? It
not, kindly advsie a way where I can write data into the fields of item
selected.

Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Folder
Dim myItem As Outlook.ContactItem

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[CustomerID] = ""ID0000001""")

myItem.Spouse = "Mrs ID000001"

myItem.Save


Your advise is appreciated.

Thank you.

TS Lim
 
T

TS Lim

Dear Sue,

Pls ignore my reply earlier on your question below. It is working now. Thank
you a lot for your prompt and precise reply.

Regards,

TS Lim



Sue Mosher said:
What specifically doesn't work? Error messages? Other symptoms? Does myItem
return the correct object?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers




TS Lim said:
After finding the item, I can read data of fields of the item. But to write
data, it still does not work. Any advise ?

TS Lim


Sue Mosher said:
Yes, that's it exactly.

:

After finding a contact item, is it possible to write data into another field
of the item ?
In the example below, after finding the item with the CustomerID field. It
try to write data into the Spouse field. Is it the right way to do it ? It
not, kindly advsie a way where I can write data into the fields of item
selected.

Dim myOlApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Folder
Dim myItem As Outlook.ContactItem

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[CustomerID] = ""ID0000001""")

myItem.Spouse = "Mrs ID000001"

myItem.Save


Your advise is appreciated.

Thank you.

TS Lim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top