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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve a contacts email address from Access XP

Status
Not open for further replies.

theismanapp

Programmer
Jul 27, 2005
5
US
The code below works when I access the contacts from the users email account. I need to access a public folder. The public folder is called "Public_contacts " under All Public Folders. Here is the code

Dim olApp As Outlook.Application
Dim objContact As ContactItem
Dim objContacts As MAPIFolder
Dim objNameSpace As NameSpace
Dim objProperty As UserProperty

Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)

Set objContact = objContacts.Items.Find("[File As] = " & """" & LastName & ", " & FirstName & """" & " and [First Name] = " & FirstName)
If Not TypeName(objContact) = "Nothing" Then
FindRequestedByEmail = objContact.Email1Address
Else
FindRequestedByEmail = "Contact Not Found"
End If

Here is the code I tried to use for the public folders and retreive an Type Mismatch error
Dim olApp As Outlook.Application
Dim objContact As ContactItem
Dim objContacts As MAPIFolder
Dim objNameSpace As NameSpace
Dim objProperty As UserProperty
Dim objNewContacts As ContactItem

Set olApp = CreateObject("Outlook.Application")
Set objNameSpace = olApp.GetNamespace("MAPI")
Set objContacts = objNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders)
Set objNewContacts = objContacts.Folders("Public_Contacts ")

'Set objContact = objContacts.Items.Find("[File As] = " & """" & LastName & ", " & FirstName & """" & " and [First Name] = " & FirstName)
Set objContact = objNewContacts.Items.Find("[File As] = " & """" & LastName & ", " & FirstName & """" & " and [First Name] = " & FirstName)
If Not TypeName(objContact) = "Nothing" Then
FindRequestedByEmail = objContact.Email1Address
Else
FindRequestedByEmail = "Contact Not Found"
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top