none
Sending Email RRS feed

  • Question

  • I have an access 2010 database that has the following code for sending an email.

         If (Len(ownermail) > 0 And (EmailBoth Or rs("payee") = "O")) Then
            Call DoCmd.SendObject(acSendReport, currentreport, acFormatRTF, ownermail, , , Subject, s, False)
         End If
         If (Len(trainermail) > 0 And (EmailBoth Or rs("payee") = "T")) Then
            Call DoCmd.SendObject(acSendReport, currentreport, acFormatRTF, trainermail, , , Subject, s, False)

    In trying to run this on a windows 8.1 machine that also has outlook 2016 running when it gets past the first email and the outlook allow message the database goes into not responding mode and never returns. Any idea of why and how to make it work?

    Dale

    Wednesday, April 13, 2016 12:10 AM

Answers

  • Hi Dale,

    Could you reproduce this issue when you send the message via Access UI? If this issue also could be reproduced, I suggest that you try to repair/update Access and Outlook to see whether the issue wax fixed.

    We also could using Outlook object model to automate the Outlook to send the email. And here is an example for your reference, please let me know whether it works for you:

     Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
              Dim objOutlook As Outlook.Application
              Dim objOutlookMsg As Outlook.MailItem
              Dim objOutlookRecip As Outlook.Recipient
              Dim objOutlookAttach As Outlook.Attachment
    
              ' Create the Outlook session.
              Set objOutlook = CreateObject("Outlook.Application")
    
              ' Create the message.
              Set objOutlookMsg  = objOutlook.CreateItem(olMailItem)
    
              With objOutlookMsg
                  ' Add the To recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
                  objOutlookRecip.Type = olTo
    
                  ' Add the CC recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add("Michael Suyama")
                  objOutlookRecip.Type = olCC
    
                 ' Add the BCC recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
                  objOutlookRecip.Type = olBCC
    
                 ' Set the Subject, Body, and Importance of the message.
                 .Subject = "This is an Automation test with Microsoft Outlook"
                 .Body = "This is the body of the message." &vbCrLf & vbCrLf
                 .Importance = olImportanceHigh  'High importance
    
                 ' Add attachments to the message.
                 If Not IsMissing(AttachmentPath) Then
                     Set objOutlookAttach = .Attachments.Add(AttachmentPath)
                 End If
    
                 ' Resolve each Recipient's name.
                 For Each ObjOutlookRecip In .Recipients
                     objOutlookRecip.Resolve
                 Next
    
                 ' Should we display the message before sending?
                 If DisplayMsg Then
                     .Display
                 Else
                     .Save
                     .Send
                 End If
              End With
              Set objOutlook = Nothing
          End Sub

    More detail about send message Via Outlook automation please refer to link below:
    https://support.microsoft.com/en-us/kb/161088

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 14, 2016 3:29 AM
    Moderator
  • Since it's an Access application the OP might not be willing to add references to Outlook.

    Replace all similar to

    Dim objOutlook As Outlook.Application

    with

    Dim objOutlook As Object

    ... and it will work in Access WITHOUT adding a reference to Outlook


    Best regards, George

    Thursday, April 14, 2016 3:53 PM

All replies

  • Is Outlook 2016 of the Click-to-Run variety delivered by Office 365?


    -Tom. Microsoft Access MVP

    Wednesday, April 13, 2016 1:43 AM
  • I believe so but not 100% positive as it not my machine.
    Wednesday, April 13, 2016 1:45 AM
  • CTR is *not* just another way to get software installed. This software runs in its own VM, and as far as I understand there is no automation between an MSI product and a CTR product.

    The closest article I could find from MSFT admitting as much is here: https://support.office.com/en-us/article/Office-2010-Click-to-Run-Known-issues-3d5a8016-6ed3-4446-9aa6-2ded79e50d0a


    -Tom. Microsoft Access MVP

    Wednesday, April 13, 2016 1:56 AM
  • Any suggestions on how to make the access database be able to send the emails? A different email client possibly? I am open to suggestions.
    Wednesday, April 13, 2016 2:04 AM
  • There is a whole alphabet soup of possibilities, including CDO, MAPI, and probably others (Redemption?).

    I know, I don't like it either, and suspect MSFT did not fully appreciate this limitation. It's a great way to kill COM-based programming (hint, hint).


    -Tom. Microsoft Access MVP

    Wednesday, April 13, 2016 2:50 AM
  • Hi Dale,

    Could you reproduce this issue when you send the message via Access UI? If this issue also could be reproduced, I suggest that you try to repair/update Access and Outlook to see whether the issue wax fixed.

    We also could using Outlook object model to automate the Outlook to send the email. And here is an example for your reference, please let me know whether it works for you:

     Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
              Dim objOutlook As Outlook.Application
              Dim objOutlookMsg As Outlook.MailItem
              Dim objOutlookRecip As Outlook.Recipient
              Dim objOutlookAttach As Outlook.Attachment
    
              ' Create the Outlook session.
              Set objOutlook = CreateObject("Outlook.Application")
    
              ' Create the message.
              Set objOutlookMsg  = objOutlook.CreateItem(olMailItem)
    
              With objOutlookMsg
                  ' Add the To recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
                  objOutlookRecip.Type = olTo
    
                  ' Add the CC recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add("Michael Suyama")
                  objOutlookRecip.Type = olCC
    
                 ' Add the BCC recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
                  objOutlookRecip.Type = olBCC
    
                 ' Set the Subject, Body, and Importance of the message.
                 .Subject = "This is an Automation test with Microsoft Outlook"
                 .Body = "This is the body of the message." &vbCrLf & vbCrLf
                 .Importance = olImportanceHigh  'High importance
    
                 ' Add attachments to the message.
                 If Not IsMissing(AttachmentPath) Then
                     Set objOutlookAttach = .Attachments.Add(AttachmentPath)
                 End If
    
                 ' Resolve each Recipient's name.
                 For Each ObjOutlookRecip In .Recipients
                     objOutlookRecip.Resolve
                 Next
    
                 ' Should we display the message before sending?
                 If DisplayMsg Then
                     .Display
                 Else
                     .Save
                     .Send
                 End If
              End With
              Set objOutlook = Nothing
          End Sub

    More detail about send message Via Outlook automation please refer to link below:
    https://support.microsoft.com/en-us/kb/161088

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 14, 2016 3:29 AM
    Moderator
  • Since it's an Access application the OP might not be willing to add references to Outlook.

    Replace all similar to

    Dim objOutlook As Outlook.Application

    with

    Dim objOutlook As Object

    ... and it will work in Access WITHOUT adding a reference to Outlook


    Best regards, George

    Thursday, April 14, 2016 3:53 PM