Results 1 to 4 of 4
  1. #1
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    102

    Sending two reports in an email through VBA


    Hello All,

    I'm working in a code to send some reports through email by clicking a single button, right now I have successfully send a single file without any issue and now I'm attempting to send two files, if you see the code, it first exports the report to PDF and then attaches it to the email.

    So far I have duplicated the exporting part so that two different documents are exported and it works fine, the thing is that I don't know how to attach both files in the outlook section, you can see my unsuccessful attempt below, any suggestions?

    Code:
    Private Sub btn_Send_Click()
    
    
    Dim oApp As Object
    Dim oEmail As Object
    Dim fileName1 As String, todayDate As String, fileName2 As String
    
    
    todayDate = Format(Date, "MMDDYYYY")
    
    
    fileName1 = "\\mxchi-fs02\danmexshr\BD\Certificaciones\Reports" & "\Report-ExpiringTop_" & todayDate & ".pdf"
    DoCmd.OutputTo acReport, "Report-ExpiringTop", acFormatPDF, fileName1, False
    
    
    fileName2 = "\\mxchi-fs02\danmexshr\BD\Certificaciones\Reports" & "\Report-ScheduledTop_" & todayDate & ".pdf"
    DoCmd.OutputTo acReport, "Report-ScheduledTop", acFormatPDF, fileName2, False
    
    
    Set oApp = CreateObject("Outlook.Application")
    Set oEmail = oApp.CreateItem(0)
    
    
    oEmail.To = DLookup("
    [Lista]", "[tbl-sendlist]", "[ID]= 1")
    oEmail.Subject = "Test"
    oEmail.Body = "Testing"
    oEmail.Attachments.Add fileName1 & fileName2
    oEmail.Send
    MsgBox "Email Sent"
        
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    More like:

    oEmail.Attachments.Add fileName1
    oEmail.Attachments.Add fileName2
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    102
    Quote Originally Posted by pbaldy View Post
    More like:

    oEmail.Attachments.Add fileName1
    oEmail.Attachments.Add fileName2
    Excellent!! that made it work! thanks a lot!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 11-07-2016, 11:18 AM
  2. Sending Reports with email body having HTML
    By CeVaEs_64 in forum Access
    Replies: 28
    Last Post: 11-26-2014, 12:13 PM
  3. Email sending
    By Steven.Allman in forum Access
    Replies: 25
    Last Post: 06-21-2010, 09:37 AM
  4. Sending reports
    By nashr1928 in forum Forms
    Replies: 3
    Last Post: 04-28-2010, 07:31 AM
  5. Sending email
    By nashr1928 in forum Reports
    Replies: 8
    Last Post: 04-27-2010, 11:14 PM

Tags for this Thread

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