Results 1 to 8 of 8
  1. #1
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    Get email recipient

    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

  2. #2
    Balge54 is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2022
    Posts
    4
    I tried your function using 'sFromName = "John.Smith@gmail.com"' and it worked; but did not work using '"sFromName = "John Smith"' nor with "Smith John".
    To my knowledge, this sounds logical as the "resolve" instruction looks for an eMail address.

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    FYI I deleted your other thread and moved this one to the forum you wanted it in. In the future, you can just report your own post and ask for it to be moved rather than duplicating it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    Thank you, I wasn't sure how to do that and I didn't want "double-post"
    Quote Originally Posted by pbaldy View Post
    FYI I deleted your other thread and moved this one to the forum you wanted it in. In the future, you can just report your own post and ask for it to be moved rather than duplicating it.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,027
    I used the code below in my email, though by that time I had a new emal open?
    Code:
                   Set objOutlookRecip = .Recipients.Add("Jim Needs - Personal")
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Balge54 is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2022
    Posts
    4
    @Welshgasman: I didn't get your point but as far the code you wrote is concerned, I would rather change to something like this:
    Code:
    Set objOutlookRecip = .Recipients.Add("Jim.Needs@xyz.com")

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,027
    Quote Originally Posted by Balge54 View Post
    @Welshgasman: I didn't get your point but as far the code you wrote is concerned, I would rather change to something like this:
    Code:
    Set objOutlookRecip = .Recipients.Add("Jim.Needs@xyz.com")
    The reason I did it that way, is if the email address changed in outlook, it would still be able to send the email.
    Your way, you would need to amend code in access, or data in a table (better), but still have to remember to do so.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Balge54 is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2022
    Posts
    4
    Right; I'm doing so every year updating my table, but i's merely for 1 or 2 guys max. The alert comes often either from the customer or by return undelivered.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 10-11-2021, 03:44 PM
  2. Replies: 11
    Last Post: 05-27-2021, 08:38 AM
  3. sending an outlook appointment to a recipient
    By DMT Dave in forum Access
    Replies: 6
    Last Post: 11-06-2020, 12:38 PM
  4. Error on SendObject method - Unknown recipient
    By Glenn_Suggs in forum Access
    Replies: 4
    Last Post: 07-11-2013, 12:11 PM
  5. Replies: 2
    Last Post: 02-04-2010, 10:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums