Results 1 to 8 of 8
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    VBA Outlook does not Recognize One or More Names

    I'm looping through a list of schools emailing them using outlook

    the vba breaks sometimes and I get this error

    Outlook does not Recognize One or More Names

    The email seems fine so I can't see why it occurs.

    it breaks on the line with .send



    Code:
    Outlook does not Recognize One or More Names

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Anyone? bump

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Are you able to determine which names are causing a problem, or if there is a common characteristic of the ones that don't work?

    One way to determine this might be to send the E-mails to one recipient at a time, rather than build a list first and send one message to multiple recipients.

    It's only a guess, but maybe it's a punctuation issue?

  4. #4
    jas0501's Avatar
    jas0501 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    15
    Rather than post the message to outbox post it to drafts when testing.

    Add debug.print in the loop and display values passed to the send line as in
    debug.print "Names is =>" & schoolName & "<="
    The last one in the immediate window will be the problem.

    Add error handling to the sub containing the loop and display the error
    Msgbox(" Error:" & err.number & " " & err.description)

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by John_G View Post
    Are you able to determine which names are causing a problem, or if there is a common characteristic of the ones that don't work?

    One way to determine this might be to send the E-mails to one recipient at a time, rather than build a list first and send one message to multiple recipients.

    It's only a guess, but maybe it's a punctuation issue?
    Each message goes through one record at a time using dao.recordset

    I have a do until rs.eof

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by jas0501 View Post
    Rather than post the message to outbox post it to drafts when testing.

    Add debug.print in the loop and display values passed to the send line as in
    debug.print "Names is =>" & schoolName & "<="
    The last one in the immediate window will be the problem.

    Add error handling to the sub containing the loop and display the error
    Msgbox(" Error:" & err.number & " " & err.description)
    I believe it may be an outlook error and not an access one - although I'm still looking into it.

  7. #7
    jas0501's Avatar
    jas0501 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    15
    Not sure where I dredged this from. Sorry for lack of attribution. You can add a sub to outlook and then debug in outlook when/if it fails.
    It has been a while since I used this. It may be the case that Office 2010 chokes on it.

    Code:
    '
    ' outlook code
    '
    
    Private Sub Application_Startup()
    Dim x As Integer
     
        x = 1
        Debug.Print "Ran this."
    End Sub
    
    
    
    Public Sub SendMessage(filename As String, _
                    recip As String, _
                    text As String, _
                    subj As String)
                    
        ' Send a message to your new contact.
        Dim olMail As Outlook.MailItem
        Set olMail = Application.CreateItem(olMailItem)
        ' Fill out & send message...
        olMail.To = recip
        olMail.Subject = subj
        olMail.Body = text
        If filename <> "" Then
            olMail.Attachments.Add filename
        End If
       olMail.Send
       
    End Sub
    Then add an outlook mail class in access


    Code:
    '
    ' access class OutlookSendMail
    '
    Option Compare Database
    Option Explicit
    '
    ' Note is object is dependend on the routine in outlook
    ' for sending email.
    '
    ' also note that for some reason code needs to be executed in
    ' outlook_startup to permit proper sendmessage calls
    '
    
    
    Dim app As Object ' early binding Outlook.Application
    
    
    Function offlineCheck() As Boolean
        offlineCheck = app.Session.offline
    End Function
    
    
    Sub outlookSendMessage(sendto As String, _
            subj As String, _
            attch As String, _
            Msg As String)
    Dim X As String
        X = app.SendMessage(attch, sendto, Msg, subj)
    End Sub
    
    Private Sub Class_Initialize()
        Set app = CreateObject("Outlook.Application")
        app.Session.Logon
    End Sub
    
    
    Private Sub Class_Terminate()
        app.Session.Logoff
        Set app = Nothing
    End Sub
    And the code to use the class


    Code:
    Public Sub setupPostOffice()
    Dim outlk As Object ' early binding OutlookSendMail
        Set outlk = New OutlookSendMail
    checkAgain:
        If outlk.offlineCheck = False Then
            MsgBox "Set Outlook Session to be Offline via:" & _
                chr(13) & chr(13) & "    File->Work_Offline" & _
                chr(13) & chr(13) & "inside Outlook."
            GoTo checkAgain
        End If
    
    
    End Sub
    
    
    Public Sub TakedownPostOffice()
    Dim outlk As Object ' early binding OutlookSendMail
        MsgBox "Reminder: To send the email you" & chr(13) & _
                "need to deselect Work offline via menu:" & chr(13) & chr(13) & _
                "      File->Work Offiline" & chr(13) & chr(13) & _
                "in Outlook or select Send All from the Send/Recieve dropdown menu."
        Set outlk = Nothing
    End Sub
    
    
    ...
    setupPostOffice
    ...
    '  loop for multiple message
    
    outlk.OutlookSendMessage_
                    filename, _
                    towho, _
                    message_final, _
                    Subject
    ...
    TakedownPostOffice
    ...

  8. #8
    jas0501's Avatar
    jas0501 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    15
    Quote Originally Posted by jas0501 View Post
    Not sure where I dredged this from. Sorry for lack of attribution. You can add a sub to outlook and then debug in outlook when/if it fails.
    It has been a while since I used this. It may be the case that Office 2010 chokes on it.
    ...
    ...
    ... this approach send doesn't work with office 2010
    ...
    ...
    ...
    [/CODE]
    Here is code that does seem to work. Note you can use .save instead of .send and the message go to the Drafts folder.

    Code:
    Private Sub cmd_SendEmail_Click()
    Dim oOutlook            As Outlook.Application
    Dim oEmailItem          As Outlook.MailItem
    Dim oEmailAttachments   As Outlook.Attachments
    
    
        On Error Resume Next
        err.Clear
        Set oOutlook = GetObject(, "Outlook.application")
        If err.Number <> 0 Then
            Set oOutlook = New Outlook.Application
        End If
        On Error GoTo errHandler
        Set oEmailItem = oOutlook.CreateItem(olMailItem)
        Set oEmailAttachments = oEmailItem.Attachments
        oEmailAttachments.Add Me.txt_Attach.value, olByValue, 1, "Test"
        oEmailAttachments.Add Me.txt_Attach.value, olByValue, 2, "Test"
        With oEmailItem
            .To = Me.txt_To
            .cc = Me.txt_CC
            .Body = Me.txt_msg
            .Subject = Me.txt_Subj
            .BCC = Me.txt_To
            .Save
        End With
        Set oEmailItem = Nothing
        Set oOutlook = Nothing
        
    errExit:
        Exit Sub
    errHandler:
        MsgBox err.Number & " : " & err.Description
        Resume errExit
    End Sub

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

Similar Threads

  1. Link existing names in Access DB to Outlook contact
    By mikejoka in forum Import/Export Data
    Replies: 1
    Last Post: 08-30-2013, 12:24 PM
  2. Access 2010 does not recognize....
    By TinaCa in forum Access
    Replies: 9
    Last Post: 01-30-2012, 06:37 AM
  3. Getting form to recognize duplicate dates
    By Remster in forum Programming
    Replies: 3
    Last Post: 09-21-2011, 03:26 AM
  4. List Box Not Recognize OnKeyPress ENTER
    By Rawb in forum Programming
    Replies: 1
    Last Post: 02-14-2011, 08:04 AM
  5. Access does not recognize field
    By Shingo in forum Reports
    Replies: 0
    Last Post: 06-25-2009, 09:17 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