Results 1 to 5 of 5
  1. #1
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95

    Dynamically Emailing Reports

    Hello,

    The following code emails a department report to the department manager each pay period. The code works great except that it opens each email one at a time, requiring the user to click "send" for each report before it will move on to the next one.

    Code:
    Private Sub Detail_Click()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("Current_Dept_List")
    If Not rs.BOF And Not rs.EOF Then
        While Not rs.EOF
    DoCmd.OpenReport "EE_Detail_Distro", acViewPreview, , "labor_worked=" & rs!Labor_worked
    DoCmd.SendObject acSendReport, "", acFormatPDF, rs!email, , , "Labor Budget Summary Report"
    DoCmd.Close
    rs.MoveNext
        Wend
    End If
    rs.Close
    
    End Sub

    Since we have over 50 departments, I am trying to save the user time by sending out all reports automatically at once and bypass the requirement of the user to click "send" between each of the 50 emails.

    Is there a way to do this by chance? The user email program is Outlook 2016.

    Thanks in advance for the help!


    Jessica

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    If you're using Outlook, you can control it via automation and have a lot more flexibility such as To lists, CC, BCC, attachments, edit message/or not, etc.
    Research "ms access send email with attachment" or similar to get code samples.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Before you try automation which should definitively work for you see if changing the Docmd.SendObject line to add false for the EditMessage parameter will work:

    DoCmd.SendObject acSendReport, "", acFormatPDF, rs!email, , , "Labor Budget Summary Report" ,"",False
    SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)

    https://docs.microsoft.com/en-us/office/vba/api/access.docmd.sendobject

    You might get the security warning but if you have a up-to-date anti-virus you should not in 2016.


    If you want to automate Outlook here is a function using late binding that I use:
    Code:
    Function vcSendEmail_Outlook_With_Attachment(sSubject As String, sTo As String, Optional sCC As String, Optional sBcc As String, Optional sAttachment As String, Optional sBody As String)
        Dim OutApp As Object
        Dim OutMail As Object
     
      
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
     
      
     
        Set OutMail = OutApp.CreateItem(0)
     
        OutMail.To = sTo
        If sCC <> "" Then OutMail.CC = sCC
        If sBcc <> "" Then OutMail.BCC = sBcc
        OutMail.Subject = sSubject
        If sBody <> "" Then OutMail.HTMLBody = sBody
    
    
        OutMail.Attachments.Add (sAttachment)
    
    
        OutMail.Display  'Send | Display
    
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Function
    Please note that you will need to save each individual (departmental) report prior to calling this function as sAttachement is the full path to the file to be attached.

    Cheers,
    Vlad

  4. #4
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    Thank you Gicu. Your code worked like a charm! I certainly do appreciate it.

  5. #5
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Glad to hear!

    Cheers,
    Vlad

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

Similar Threads

  1. Emailing Reports
    By nzlowie in forum Reports
    Replies: 7
    Last Post: 01-24-2016, 09:02 AM
  2. Emailing Reports
    By ssworthi in forum Reports
    Replies: 4
    Last Post: 08-25-2015, 04:44 PM
  3. Emailing Muliple Reports
    By GWILKIE in forum Access
    Replies: 4
    Last Post: 10-25-2013, 02:46 PM
  4. Emailing reports from access
    By doopml in forum Programming
    Replies: 3
    Last Post: 10-24-2012, 11:18 AM
  5. Emailing forms or reports
    By dcecil in forum Reports
    Replies: 6
    Last Post: 12-16-2009, 07:57 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