Reputation: 119
I have a userform with 3 textboxes and 1 button. I want to put an outlook alias into textbox1 (txtPID) and return the display type and email in boxes 2 & 3 (txtName & txtEmail)
this appears to connect to outlook and pull information but it's not searching the alias given in textbox 1
Load UsrFrmNewRep
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olGAL As Outlook.AddressList
Dim olMember As Outlook.AddressEntry
Dim olAliasName As String
Dim exchuser As Outlook.ExchangeUser
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olGAL = olNS.AddressLists("Global Address List")
olAliasName = UsrFrmNewRep.txtPID.Value
Set olMember = olGAL.AddressEntries(olAliasName)
Set exchuser = olMember.GetExchangeUser
If Not exchuser Is Nothing Then
UsrFrmNewRep.txtName.Value = exchuser.DisplayType
UsrFrmNewRep.txtEmail.Value = exchuser.PrimarySmtpAddress
End If
End Sub
i'm sure i'm not referencing something correctly i'm just not sure what.
Thanks
Upvotes: 0
Views: 446
Reputation: 66215
Instead of using olGAL.AddressEntries(olAliasName)
, use olNS.CreateRecipient(olAliasName)
/ Recipient.Resolve
/ set olMember = Recipient.AddressEntry
Upvotes: 1