Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help - How Do i Access the Outlook Global Address Book in Visual basic 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I require to get the list of details (name,phone,email addr etc) from the outlook global address book , in to my Visual basic program. ie i would like to create an array of data (ie 1 row for each entry) , so that i can page through and search for addresses based on any critera) like you could do if the list existed on a table in a database.

I have tried the MAPI components , but only seem to be abel to send a message. no where can i find somthing that gives me access the the address books

Can anyone help ?

 
Well, I have found a couple of ways to obtain, update, and manipulate data out of Outlook. There should be a way to dim an object say objAddress as Addresslist. I think that this would call up the global address list. There are two available Addresslist and Addresslists.

Below is the code that I have been using to get the email address of a vendor that is associated with a particular project. In contrast you can cycle through all contacts and append the info to a table.

Try for more tips.

Function LU_Deal()

Get_Contact:
Dim appOutLook As Outlook.Application
Dim objContact As ContactItem
Dim objNameSpace As NameSpace
Dim objFolder As MAPIFolder
Dim stDRN As String

stDRN = [Forms]![frmProjectSummary]![DealerRepName]

Set appOutLook = CreateObject("Outlook.Application")
Set objNameSpace = appOutLook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFolderContacts)

With objFolder.Items(stDRN)
LU_Deal = .Email1Address
End With

Set appOutLook = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing

Exit Function

Hope this helps...

jelwood01
 
AAAh a step in the right direction , but now i cannot get access the the details of each recipient like the Phone no, fax no ,email , building etc.
if i use olAE.Details , it displays the properties box for the current user , but i need to get the details displayed in the properties into the app ..

here is my code:
Private Sub Command1_Click()
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olAL As Outlook.AddressList
Dim olAE As Outlook.AddressEntry

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")

For Each olAL In olNS.AddressLists

On Error Resume Next
olAL.AddressEntries.Sort
On Error GoTo 0
olAL.AddressEntries.GetFirst
currentaddressbook = olAL.Name
AddCount = olAL.AddressEntries.Count

If currentaddressbook = "Global Address List" Then
For Each olAE In olAL.AddressEntries
With olAE
vName = .Name
vaddr = .Address
vDispType = .DisplayType
vType = .Type
vSesion = .Session
vID = .ID
Debug.Print vDispType, vName
If vDispType = 0 Then .Details 'this displays the porperties dilog, but i need to get the 'info into variables.
End With
Next
End If
Next
Set olApp = Nothing
End Sub
 
After a little fiddling the only pieces that I can grab are names, emails, and class. There should be a way to access the info about the individual. It might be contained somewhere else and the .details pulls that up based on a relation to the ID of each individual.

I'll keep digging to pull out more info but we have a start here.

Here is how I tweaked your code to run through the address book and display name, email, and class in a message box (Also you can append each string to a field in a recordset):

Private Sub cmdOLAdd_Click()

Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olAL As Outlook.AddressList
Dim olAE As Outlook.AddressEntry
Dim currentAddressbook As String
Dim stName, stClass, stAdd, stID As String

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")

For Each olAL In olNS.AddressLists

currentAddressbook = olAL.name

If currentAddressbook = "Global Address List" Then
For Each olAE In olAL.AddressEntries
With olAE
stID = .ID
stClass = .Class
stName = .name
stAdd = .Address
End With
MsgBox stID & vbTab & stName & vbTab & stAdd & vbTab & stClass
Next
End If
Set olApp = Nothing
Next

End Sub
 
Awesome ! Thanks , i keep bashing at it my self , and i'll let u know if i find anything.

Hope u or i find somthing soon.
 
Greetings:

support.microsoft.com article Q179083 has an excellent example of getting information from the global address book using collaborative data objects (CDO).

Hope that helps!

Keyser Soze

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top