theismanapp
Programmer
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
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