hangover


This might not be the right forum for this question given that it mainly concerns Outlook (although I am accessing it from VFP), but I am hoping that one of you smart and helpful people may know the answer ...

I am trying to obtain to populate a VFP table with the details that I can see in my Outlook 2002 address book.

I have had some success at obtaining details such as Name, Email Address and Type via the AddressEntry objects in the "Global Address List" AddressList object.

But there are numerous other details which I can see in the Outlook Address book but which I have been unable to obtain programatically: First Name, Last Name and Address (on the General tab); various phone/fax numbers (on the Phone/Notes tab) and numerous email addresses (on the E-mail Addresses tab). Can anyone tell me where I can obtain these or at least point me in the right direction





Re: Outlook contact details

Naomi Nosonovsky


I played with it a bit at home when I was testing this code http://www.berezniker.com/display/VFP/Accessing+Outlook+Global+Address+list

The idea is to use AMEMBERS() and loop through the properties. I don't have this code right now, but I hope you can get the idea.






Re: Outlook contact details

dni

You may try reverse of :

http://support.microsoft.com/kb/269617







Re: Outlook contact details

Tamar E. Granor

Here's a program from my book on automating Outlook. This reads some of the information for each contact and puts each into a new record:

* MakeContactList.PRG
* c 2000, Tamar E. Granor and Della Martin
* From: Microsoft Office Automation with Visual FoxPro
* Hentzenwerke Publishing. www.hentzenwerke.com

* Read Outlook contact information into a cursor
#DEFINE olContacts 10
#DEFINE olNone 0
#DEFINE olHome 1
#DEFINE olBusiness 2
#DEFINE olOther 3

LOCAL oNameSpace, oContacts, oContact
LOCAL cFirst, cLast, cAddr, cPhone

IF VarType(oOutlook) <> "O"
* Start or connect to Outlook
* Make it public for demonstration purposes.
RELEASE oOutlook
PUBLIC oOutlook
oOutlook = CreateObject("Outlook.Application")
ENDIF
oNameSpace = oOutlook.GetNameSpace("MAPI")

* Get Contacts folder
oContacts= oNameSpace.GetDefaultFolder( olContacts )

* Create a cursor to hold contact information
CREATE CURSOR ContactInfo ;
(cFirstName C(15), cLastName C(20), mAddress M, cPhoneNum C(30))

* Go through contacts
FOR EACH oContact IN oContacts.Items
WITH oContact
cFirst = .FirstName
cLast = .LastName
cPhone = .PrimaryTelephoneNumber

* Choose the right address. If the primary phone number is empty,
* pick up the phone number associated with this address.
DO CASE
CASE .SelectedMailingAddress = olHome
cAddr = .HomeAddress
IF EMPTY(cPhone)
cPhone = .HomeTelephoneNumber
ENDIF
CASE .SelectedMailingAddress = olBusiness
cAddr = .BusinessAddress
IF EMPTY(cPhone)
cPhone = .BusinessTelephoneNumber
ENDIF
CASE .SelectedMailingAddress = olOther
cAddr = .OtherAddress
IF EMPTY(cPhone)
cPhone = .OtherTelephoneNumber
ENDIF
CASE .SelectedMailingAddress = olNone
cAddr = ""
ENDCASE

INSERT INTO ContactInfo VALUES (cFirst, cLast, cAddr, cPhone)
ENDWITH
ENDFOR

* Show the results
BROWSE

RETURN




Re: Outlook contact details

hangover

Thankyou all very much for your responses.

Naomi, I'm afraid that link pretty much replicates what I am doing already. The trouble is that the additional properties that I wish to obtain do not appear to be properties of the AddressEntry object.

DNI and Tamar - I have tried the contact object too but it still does not seems to have any of the relevant properties. When I run Tamar's code I get the following Program Error on the line cFirst = .FirstName: "OLE error code 0x800200006: Unknown name."

When I look at the oContact object it does not have any of the specified properties such as .FirstName, .LastName or .PrimaryTelephoneNumber. I've included a complete list of its properties and methods below in case this helps.

Actions
AddMember ()
AddMembers ()
Application
Attachments
BillingInformation
Body
Categories
CheckSum
Class
Close ()
Companies
ConversationIndex ()
ConversationTopic ()
Copy ()
CreationTime
Delete ()
Display ()
DLName
DownloadState
EntryID
FormDescription
GetInspector
GetMember ()
Importance
IsConflict
ItemProperties
LastModificationTime
Links
MAPIOBJECT
MarkForDownload
MemberCount
Members
MessageClass
Mileage
Move ()
NoAging
OneOffMembers
OutlookInternalVersion
OutlookVersion
Parent
PrintOut ()
RemoveMember ()
RemoveMembers ()
Save ()
SaveAs ()
Saved
Sensitivity
Session
ShowCategoriesDialog ()
Size
Subject
UnRead
UserProperties






Re: Outlook contact details

CetinBasoz

Are you checking DistList object or a similar one

oContacts there is a ContactItem object and it does have FirstName , LastName ... properties (as documented in outlook VBA help).





Re: Outlook contact details

hangover

Ah, thanks Cetin - I hadn't appreciated that the folder could contain distribution lists (i.e. DistListItem objects) as well as individual contacts.

If I amend Tamar's program by adding the code below to avoid such lists, then I do encounter a number of ContactItem objects with the properties I am looking for (.FirstName, .LastName, etc.)

Code Snippet

IF TYPE ("oContact.FirstName") = "U"

LOOP

ENDIF

The problem is that these are the contacts in my personal Contacts folder in Outlook. Whereas I am trying to obtain the contact details of the contacts in the Global Address List (i.e. the contacts list which everyone in my organisation has access to). Do you know where I can find these






Re: Outlook contact details

CetinBasoz

No I don't do much outlook automation nor know outlook itself (I only use it for emailing and even that is cumbersome, express was better).

I think you could find what you want in VBA help.





Re: Outlook contact details

hangover

Ta, I came across this discussion on another forum which indicates that in order to do what I want requires CDO (which I've never come across before) and is somewhat involved. I think I might have to put this on the backburner for now.






Re: Outlook contact details

CraigBoyd

hi hangover,

I'm a little confused. Why won't the following work for you

Code Snippet

oApp = Createobject("Outlook.Application")

oNS = oApp.GetNamespace("mapi")

oAL = oNS.AddressLists("Global Address List") && oNS.AddressLists(1)

For j = 1 To oAL.AddressEntries.Count

m.Contact = oAL.AddressEntries(j).GetContact

m.Contact.Account

m.Contact.Actions

m.Contact.Anniversary

m.Contact.Application

m.Contact.AssistantName

m.Contact.AssistantTelephoneNumber

m.Contact.Attachments

m.Contact.AutoResolvedWinner

m.Contact.BillingInformation

m.Contact.Birthday

m.Contact.Body

m.Contact.Business2TelephoneNumber

m.Contact.BusinessAddress

m.Contact.BusinessAddressCity

m.Contact.BusinessAddressCountry

m.Contact.BusinessAddressPostOfficeBox

m.Contact.BusinessAddressPostalCode

m.Contact.BusinessAddressState

m.Contact.BusinessAddressStreet

m.Contact.BusinessCardLayoutXml

m.Contact.BusinessCardType

m.Contact.BusinessFaxNumber

m.Contact.BusinessHomePage

m.Contact.BusinessTelephoneNumber

m.Contact.CallbackTelephoneNumber

m.Contact.CarTelephoneNumber

m.Contact.Categories

m.Contact.Children

m.Contact.Class

m.Contact.Companies

m.Contact.CompanyAndFullName

m.Contact.CompanyLastFirstNoSpace

m.Contact.CompanyLastFirstSpaceOnly

m.Contact.CompanyMainTelephoneNumber

m.Contact.CompanyName

m.Contact.ComputerNetworkName

m.Contact.Conflicts

m.Contact.ConversationIndex

m.Contact.ConversationTopic

m.Contact.CreationTime

m.Contact.CustomerID

m.Contact.Department

m.Contact.DownloadState

m.Contact.Email1Address

m.Contact.Email1AddressType

m.Contact.Email1DisplayName

m.Contact.Email1EntryID

m.Contact.Email2Address

m.Contact.Email2AddressType

m.Contact.Email2DisplayName

m.Contact.Email2EntryID

m.Contact.Email3Address

m.Contact.Email3AddressType

m.Contact.Email3DisplayName

m.Contact.Email3EntryID

m.Contact.EntryID

m.Contact.FTPSite

m.Contact.FileAs

m.Contact.FirstName

m.Contact.FormDescription

m.Contact.FullName

m.Contact.FullNameAndCompany

m.Contact.Gender

m.Contact.GetInspector

m.Contact.GovernmentIDNumber

m.Contact.HasPicture

m.Contact.Hobby

m.Contact.Home2TelephoneNumber

m.Contact.HomeAddress

m.Contact.HomeAddressCity

m.Contact.HomeAddressCountry

m.Contact.HomeAddressPostOfficeBox

m.Contact.HomeAddressPostalCode

m.Contact.HomeAddressState

m.Contact.HomeAddressStreet

m.Contact.HomeFaxNumber

m.Contact.HomeTelephoneNumber

m.Contact.IMAddress

m.Contact.ISDNNumber

m.Contact.Importance

m.Contact.InitialS

m.Contact.InternetFreeBusyAddress

m.Contact.IsConflict

m.Contact.IsMarkedAsTask

m.Contact.ItemProperties

m.Contact.JobTitle

m.Contact.Journal

m.Contact.Language

m.Contact.LastFirstAndSuffix

m.Contact.LastFirstNoSpace

m.Contact.LastFirstNoSpaceAndSuffix

m.Contact.LastFirstNoSpaceCompany

m.Contact.LastFirstSpaceOnly

m.Contact.LastFirstSpaceOnlyCompany

m.Contact.LastModificationTime

m.Contact.LastName

m.Contact.LastNameAndFirstName

m.Contact.Links

m.Contact.MailingAddress

m.Contact.MailingAddressCity

m.Contact.MailingAddressCountry

m.Contact.MailingAddressPostOfficeBox

m.Contact.MailingAddressPostalCode

m.Contact.MailingAddressState

m.Contact.MailingAddressStreet

m.Contact.ManagerName

m.Contact.MarkForDownload

m.Contact.MessageClass

m.Contact.MiddleName

m.Contact.Mileage

m.Contact.MobileTelephoneNumber

m.Contact.NetMeetingAlias

m.Contact.NetMeetingServer

m.Contact.NickName

m.Contact.NoAging

m.Contact.OfficeLocation

m.Contact.OrganizationalIDNumber

m.Contact.OtherAddress

m.Contact.OtherAddressCity

m.Contact.OtherAddressCountry

m.Contact.OtherAddressPostOfficeBox

m.Contact.OtherAddressPostalCode

m.Contact.OtherAddressState

m.Contact.OtherAddressStreet

m.Contact.OtherFaxNumber

m.Contact.OtherTelephoneNumber

m.Contact.OutlookInternalVersion

m.Contact.OutlookVersion

m.Contact.PagerNumber

m.Contact.Parent

m.Contact.PersonalHomePage

m.Contact.PrimaryTelephoneNumber

m.Contact.Profession

m.Contact.PropertyAccessor

m.Contact.RadioTelephoneNumber

m.Contact.ReferredBy

m.Contact.ReminderOverrideDefault

m.Contact.ReminderPlaySound

m.Contact.ReminderSet

m.Contact.ReminderSoundFile

m.Contact.ReminderTime

m.Contact.Saved

m.Contact.SelectedMailingAddress

m.Contact.Sensitivity

m.Contact.Session

m.Contact.Size

m.Contact.Spouse

m.Contact.Subject

m.Contact.Suffix

m.Contact.TTYTDDTelephoneNumber

m.Contact.TaskCompletedDate

m.Contact.TaskDueDate

m.Contact.TaskStartDate

m.Contact.TaskSubject

m.Contact.TelexNumber

m.Contact.Title

m.Contact.ToDoTaskOrdinal

m.Contact.UnRead

m.Contact.User1

m.Contact.User2

m.Contact.User3

m.Contact.User4

m.Contact.UserProperties

m.Contact.WebPage

m.Contact.YomiCompanyName

m.Contact.YomiFirstName

m.Contact.YomiLastName

ENDFOR






Re: Outlook contact details

CraigBoyd

As for the CDO... I found some code, I think it might have been on the MSDN. Anyways the code was in VB, but I quickly transposed it, added the constant to it and came up with the below code (I can't post the constants because of their length). Can you give it a go and see if it works. I'm not running exchange at this end so I can't test it at the moment, but I thought it might help.

Code Snippet

LOCAL objSession As MAPI.Session

LOCAL objAddrEntries As AddressEntries

LOCAL objAddressEntry As AddressEntry

LOCAL objFilter As AddressEntryFilter

objSession=thisform.olecontrol1

objSession.Logon()

objAddrEntries = objSession.AddressLists("Global Address List").AddressEntries

objFilter = objAddrEntries.Filter

objFilter.Fields.Add(CdoPR_SURNAME, "LastName")

objFilter.Fields.Add(CdoPR_GIVEN_NAME, "FirstName")

For Each objAddressEntry In objAddrEntries

objAddressEntry.Name

"E-address: " + objAddressEntry.Address

"Given Name: " + objAddressEntry.Fields(CdoPR_GIVEN_NAME).Value

"Initials: " + objAddressEntry.Fields(CdoPR_INITIALS).Value

"Surname: " + objAddressEntry.Fields(CdoPR_SURNAME).Value

"Display Name: " + objAddressEntry.Fields(CdoPR_DISPLAY_NAME).Value

"Alias: " + objAddressEntry.Fields(CdoPR_ACCOUNT).Value

"Title: " + objAddressEntry.Fields(CdoPR_TITLE).Value

"Company Name: " + objAddressEntry.Fields(CdoPR_COMPANY_NAME).Value

"Office Location: " + objAddressEntry.Fields(CdoPR_OFFICE_LOCATION).Value

"Office Phone 1: " + objAddressEntry.Fields(CdoPR_OFFICE_TELEPHONE_NUMBER).Value

"Office Phone 2: " + objAddressEntry.Fields(CdoPR_OFFICE2_TELEPHONE_NUMBER).Value

"Business Fax: " + objAddressEntry.Fields(CdoPR_BUSINESS_FAX_NUMBER).Value

"Mobile Phone: " + objAddressEntry.Fields(CdoPR_MOBILE_TELEPHONE_NUMBER).Value

"Pager: " + objAddressEntry.Fields(CdoPR_PAGER_TELEPHONE_NUMBER).Value

"Assistant: " + objAddressEntry.Fields(CdoPR_ASSISTANT).Value

"Assistant Phone: " + objAddressEntry.Fields(CdoPR_ASSISTANT_TELEPHONE_NUMBER).Value

"Home Phone 1: " + objAddressEntry.Fields(CdoPR_HOME_TELEPHONE_NUMBER).Value

"Home Phone 2: " + objAddressEntry.Fields(CdoPR_HOME2_TELEPHONE_NUMBER).Value

"Home Fax: " + objAddressEntry.Fields(CdoPR_HOME_FAX_NUMBER).Value

"Home Street: " + objAddressEntry.Fields(CdoPR_HOME_ADDRESS_STREET).Value

"Home City: " + objAddressEntry.Fields(CdoPR_HOME_ADDRESS_CITY).Value

"Home State: " + objAddressEntry.Fields(CdoPR_HOME_ADDRESS_STATE_OR_PROVINCE).Value

"Home Postal Code: " + objAddressEntry.Fields(CdoPR_HOME_ADDRESS_POSTAL_CODE).Value

"Home Country: " + objAddressEntry.Fields(CdoPR_HOME_ADDRESS_COUNTRY).Value

"Manager Name: " + objAddressEntry.Fields(CdoPR_MANAGER_NAME).Value

"Manager Name: " + objAddressEntry.Manager

ENDFOR

objSession.Logoff()

objFilter = NULL

objAddrEntries = NULL

objSession = NULL






Re: Outlook contact details

MarciaAkins

hangover wrote:

I am trying to obtain to populate a VFP table with the details that I can see in my Outlook 2002 address book.

I have had some success at obtaining details such as Name, Email Address and Type via the AddressEntry objects in the "Global Address List" AddressList object.

But there are numerous other details which I can see in the Outlook Address book but which I have been unable to obtain programatically: First Name, Last Name and Address (on the General tab); various phone/fax numbers (on the Phone/Notes tab) and numerous email addresses (on the E-mail Addresses tab). Can anyone tell me where I can obtain these or at least point me in the right direction

You may want to download the White Paper and code samples from my conference session called "Office Automation With VFP" on the tools and utilities page at http:\\www.tightlinecomputers.com. One of the code samples is reading and send e-mail using Outlook Automation and the sample form pops up a form that is populated from the Outlook Address Book.






Re: Outlook contact details

hangover

Thanks Craig.

The first code crashes on the line m.Contact = oAL.AddressEntries(j).GetContact with the Program Error: "OLE error code 0x80020006: Unknown name." (AddressEntries(j) does not have a GetContact method).

The second code crashes on the line objSession=thisform.olecontrol1 with the Program Error: "THISFORM can only be used within a method."

If I amend the first few lines as below it crashes on the line objFilter = objAddrEntries.Filter with the Program Error: "OLE error code 0x80020006: Unknown name." (objAddrEntries does not have a Filter property).

Code Snippet

poOutlook = CREATEOBJECT ("Outlook.application")

objAddrEntries = poOutlook.GetNameSpace("MAPI").AddressLists("Global Address List").AddressEntries

objFilter = objAddrEntries.Filter

Dom




Re: Outlook contact details

hangover

You may want to download the White Paper and code samples from my conference session called "Office Automation With VFP" on the tools and utilities page at http:\\www.tightlinecomputers.com. One of the code samples is reading and send e-mail using Outlook Automation and the sample form pops up a form that is populated from the Outlook Address Book

Many thanks Marcia - I will take a look at this over the weekend.






Re: Outlook contact details

CraigBoyd

As for the THISFORM error you can see that it was just a bonehead slip on my part... I was testing some different scenarios on this problem. One of those scenarios had me using the MS ActiveX for simple MAPI... which is where the THISFORM came from.

As for the other errors you are seeing... they surprise me. I mean it is as if you are getting a completely different object trying to access Exchange. That's interesting to say the least and a little disconcerting. I may install Exchange on one of my servers at this end to mess with this some more if I find the time. For now I guess I can only say that both solutions I posted above (well at least the principles involved) appear to have been used by many other developers to access the information you are looking for from Exchange. While MSDN has some faulty samples on it, I can't imagine that they got it completely wrong. Perhaps it's a version problem Such as certain properties and methods being added later or having been deprecated prior I can't think of a good reason that neither solution worked at all for you (I mean, obviously after you removed my mistake and added the constants for the second solution).

Well, I wish you luck and I hope you will come back here and post the solution when you find it. Sorry I couldn't be of more help. Just for the heck of it... what version of Exchange and Outlook are you working with here