How do I use VBScript to read the fields in an Outlook Contact For

P

Paul DBZ

I am a newbie with VBScript so please excuse my ignorance. I am trying to
use VBScript to read the value of several fields in an Outlook Custom Contact
Form and write the value of those fields to an Excel spreadsheet. I don't
understand how to reference the fields. For example, when I use the code
below, I get an error message: "The object doesn't support this property or
Method: 'objItems.HomePhone'. Why is objItems.Count a valid reference yet
objItems.HomePhone causes an error?

Thank you in advance! Paul

Dim objNameSpace
Dim objFolder
Dim objItems
Dim lngCount
Dim strASCII

Set objNameSpace = Application.GetNamespace("MAPI")
Set objFolder = objNameSpace.Folders("Personal Folders").Folders("Contacts")
Set objItems = objFolder.Items
lngCount = objItems.Count
strASCII = objItems.HomePhone
 
H

Hollis D. Paul

I am a newbie with VBScript so please excuse my ignorance. I am trying to
use VBScript to read the value of several fields in an Outlook Custom Contact
Form and write the value of those fields to an Excel spreadsheet. I don't
understand how to reference the fields. For example, when I use the code
below, I get an error message: "The object doesn't support this property or
Method: 'objItems.HomePhone'. Why is objItems.Count a valid reference yet
objItems.HomePhone causes an error?

Thank you in advance! Paul

Dim objNameSpace
Dim objFolder
Dim objItems
Dim lngCount
Dim strASCII

Set objNameSpace = Application.GetNamespace("MAPI")
Set objFolder = objNameSpace.Folders("Personal Folders").Folders("Contacts")
Set objItems = objFolder.Items
lngCount = objItems.Count
strASCII = objItems.HomePhone
First, once you get the objectItems object, you have to loop through it to get
an individual item. Only then can you go for the value of an Outlook property.

Read the following page to find out how to get the value from an Outlook
property;


Correct syntax for accessing Microsoft Outlook property and control values and
writing events that respond to changes in properties or control values
http://www.outlookcode.com/d/propsyntax.htm

Hollis D. Paul [MVP - Outlook]
Mukilteo, WA USA
 
S

Sachin Sancheti

You would have to use individual item to access its property.
In the code which you are using

strASCII = objItems.HomePhone
Don't use objItems. Its a collection of all the items hence it won't
have the HomePhone Prooperty.
Loop through the collection either using for each or simple counter
based for loop access item and then use HomePhone or other properties.

For i =1 to objItems.count
strASCII = objItems(i).HomePhone
Next
 
P

Paul DBZ

Thank you Paul. I have a follow up question regarding the name of form
fields. When I am in the Form Design Mode and view the field properties for
a field, the Name of the field has spaces in it (e.g., Home Phone). Is the
programmatic name of the field simply HomePhone (e.g., Item.HomePhone)? In
other words, can I make the assumption that the "Programmitic Field Name" is
always identical to the "Properties Field Name" with the spaces removed?

Thanks,
Paul

Hollis D. Paul said:
I am a newbie with VBScript so please excuse my ignorance. I am trying to
use VBScript to read the value of several fields in an Outlook Custom Contact
Form and write the value of those fields to an Excel spreadsheet. I don't
understand how to reference the fields. For example, when I use the code
below, I get an error message: "The object doesn't support this property or
Method: 'objItems.HomePhone'. Why is objItems.Count a valid reference yet
objItems.HomePhone causes an error?

Thank you in advance! Paul

Dim objNameSpace
Dim objFolder
Dim objItems
Dim lngCount
Dim strASCII

Set objNameSpace = Application.GetNamespace("MAPI")
Set objFolder = objNameSpace.Folders("Personal Folders").Folders("Contacts")
Set objItems = objFolder.Items
lngCount = objItems.Count
strASCII = objItems.HomePhone
First, once you get the objectItems object, you have to loop through it to get
an individual item. Only then can you go for the value of an Outlook property.

Read the following page to find out how to get the value from an Outlook
property;


Correct syntax for accessing Microsoft Outlook property and control values and
writing events that respond to changes in properties or control values
http://www.outlookcode.com/d/propsyntax.htm

Hollis D. Paul [MVP - Outlook]
Mukilteo, WA USA
 
H

Hollis D. Paul

can I make the assumption that the "Programmitic Field Name" is
always identical to the "Properties Field Name" with the spaces removed?
That is certainly the best bet, but doesn't always work. Go to
http://www.dimastr.com/ and take a look at OutlookSpy. That will always
tell you the real name. Don't think it costs much, but that and
Redemption will save you a whole lot of trouble, and well worth the
investment if you design a lot of forms.

There is also a utility from microsoft called something like MDBvue, that
lets you see the true names of fields.

As an Ad Hoc method of finding the real names, you can drop a control on
the development space, and then do a look-up of the field to bind it to.

Hollis D. Paul [MVP - Outlook]
Mukilteo, WA USA
 

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