I have the following code in my form which I want to work with partial name to look in Outlook and resolve the name.
It current runs through the code but stops before it resolves itself, this happens even if I enter the name as it's found in Outlook:
Code:
Private Sub RequestByPerson_LostFocus()
If IsNull(Me.RequestByPerson) Or Me.RequestByPerson = vbNullString Then
MsgBox "The Request by Person cannot be blank.", vbOKOnly, "Requestor Required"
Me.RequestByPerson.SetFocus
Exit Sub
End If
If Not IsNull(Me.RequestByPerson) Or Me.RequestByPerson <> vbNullString Then
Dim sName As String
sName = ResolveDisplayName(Me.RequestByPerson) 'this calls the function below to Resolve the name entered
If sName <> "" And sName <> Me.RequestByPerson Then
Me.RequestByPerson = sName
ElseIf sName = "" Then
Exit Sub
End If
End Sub
Code:
Public Function ResolveDisplayName(sFromName) As String
On Error GoTo ErrorHandler
Dim OLApp As Object 'Outlook.Application
Dim oRecip As Object 'Outlook.Recipient
Dim oEU As Object 'Outlook.ExchangeUser
Dim oEDL As Object 'Outlook.ExchangeDistributionList
Set OLApp = CreateObject("Outlook.Application")
Set oRecip = OLApp.Session.CreateRecipient(sFromName) 'it goes as far as here and exits - I can't seem to find a way to capture the error properly, even though there really shouldn't be an error
oRecip.Resolve
If oRecip.Resolved Then
ResolveDisplayName = oRecip.Name
End If
Exit Function
ErrorHandler:
Exit Function
End Function