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!

OL Address Book

Status
Not open for further replies.

colriver

Programmer
Oct 24, 2000
6
US
Hello,
Does anyone know how to retrieve a selected Recipient Address from the Outlook?
Address book in VB? I can show the address book, but cannot get the address
selected into a Control. I have tried everything programmatically and searched
ever site but
Cannot find any information on this subject. I would be grateful for any help
You can give me.

I show the address book with the MAPI Show property.

MAPIMessages1.Show
lvwCC.ListItems.Add = ???


Thank you
 
The sample below may need to be modified but should give you the idea.

Steve King



Public Function GetContact(strName As String)

On Error Resume Next

Dim oApp As Outlook.Application
Dim myNameSpace As NameSpace
Dim myAddressLists As AddressLists
Dim myAddressList As AddressList
Dim myAddrEntries As AddressEntries
Dim myEntry As AddressEntry
Dim intNameLen As Integer
Dim intCnt As Integer
Dim intCnt2 As Integer
Dim strUser As String
Dim strTempAddr As String

Set oApp = GetOutlook()
Set myNameSpace = oApp.GetNamespace("MAPI")
intNameLen = Len(strName)

For Each myAddressList In myNameSpace.AddressLists
If myAddressList.Name = "Contacts" _
Or myAddressList.Name = "Personal Address Book" Then
For Each myEntry In myAddressList.AddressEntries
If InStr(1, myEntry.Name, strName) Then
strTempAddr = myEntry.Address
If InStr(1, strTempAddr, "=") Then
strTempAddr = GetShortAddr(myEntry.Members(intCnt).Address)
End If

' Details pops up the properties dialog
'myEntry.Details (0)
'Debug.Print myEntry.Name & " (" & myEntry.Address & ")"
'If myEntry.DisplayType
strUser = myEntry.Name & " (" & strTempAddr & ")"
strTempAddr = ""
Select Case myEntry.DisplayType
Case olDistList, olPrivateDistList '4, 5
Debug.Print " Distribution List: " & strUser
For intCnt = 1 To myEntry.Members.Count
strTempAddr = myEntry.Members(intCnt).Address
If InStr(1, strTempAddr, "=") Then
strTempAddr = GetShortAddr(myEntry.Members(intCnt).Address)
End If
Debug.Print " Member: " & myEntry.Members(intCnt).Name _
& " (" & strTempAddr & ")"
strTempAddr = ""
Next intCnt
Case olRemoteUser '6
Debug.Print " Remote User: " & strUser

Case olUser '0
Debug.Print " User: " & strUser
Case Else
Debug.Print " Unknown " & strUser
End Select
End If
Next myEntry
End If
Next myAddressList

End Function
Public Function GetOutlook() As Outlook.Application

Dim MyOutlook As Outlook.Application
Dim OutlookWasNotRunning As Boolean
On Error Resume Next ' Defer error trapping.
Set MyOutlook = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then OutlookWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.

If OutlookWasNotRunning = True Then
MyOutlook.Application.Quit
End If

Set GetOutlook = MyOutlook.Application
Set MyOutlook = Nothing ' Release reference to the

End Function Professional growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top