Results 1 to 3 of 3
  1. #1
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125

    Attach Two Reports (1 Dynamic and 1 Static)

    Good evening,

    I am trying to attach two reports to one email when I click a button, please could someone review the Syntax as below and let me know what I'm doing wrong:-

    Private Sub Command134_Click()

    10 On Error GoTo Command134_Click_Error
    20 If Me.Dirty Then Me.Dirty = False
    '30 MsgBox "A Copy of the Quote was saved to the C Drive PDF Folder", vbInformation
    Dim strSQL As String
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strToSQL As String
    Dim strCPON As String
    Dim strSOP As String
    Dim strCN As String

    Dim strSubject As String
    Dim strMessage As String
    Dim strReportname1 As String
    Dim strReportname2 As String
    Dim strPath As String

    34 strCN = Me.ClientName
    35 strCPON = Me.ClientPONumber
    37 strSOP = Me.SalesOrderDatePromised
    40 strToSQL = Me.EmailTo
    50 strSubject = "Pro Forma Invoice - " & [ClientPONumber] & ""
    60 strReportname1 = "rptSalesOrderAcknowledgementProforma"
    70 strPath = "C:\PDF Reports" & "Pro Forma Invoice - " & strCPON & ".pdf"
    71 strReportname2 = "rptBD"
    72 strPath = "C:\PDF Reports" & "Bank Details" & ".pdf"

    80 DoCmd.OpenReport strReportname1, acPreview, "", "[SalesOrderNumber]=[Forms]![frmSalesOrders].[Form]![SalesOrderNumber]"
    90 DoCmd.OutputTo acOutputReport, strReportname1, acFormatPDF, "C:\PDF Reports" & "Pro Forma Invoice - " & strCPON & ".pdf"

    91 DoCmd.OpenReport strReportname2, acPreview, "", "[SalesOrderNumber]=[Forms]![frmSalesOrders].[Form]![SalesOrderNumber]"
    92 DoCmd.OutputTo acOutputReport, strReportname2, acFormatPDF, "C:\PDF Reports" & "Bank Details - " & strCPON & ".pdf"

    100 strMessage = "Dear " & strCN & "," & vbNewLine & vbNewLine & "This is to acknowledge that we received your Purchase Order number: " & strCPON & "." & vbNewLine & vbNewLine & "Pro Forma is attached together with our bank details. " & vbNewLine & vbNewLine & "Estimated Completion Date is: " & strSOP & "."

    110 Set OutApp = CreateObject("Outlook.Application")
    120 Set OutMail = OutApp.CreateItem(0)

    130 On Error Resume Next

    160 With OutMail
    170 .To = strToSQL
    '190 .CC = strCC1 & ";" & strCC2
    180 .Subject = strSubject
    190 .Attachments.Add strReportname1, "rptSalesOrderAcknowledgementProforma"
    195 .Attachments.Add strReportname2, "rptBD"
    200 .Body = strMessage


    210 .Display
    220 End With

    230 On Error GoTo 0
    240 Exit Sub

    Command134_Click_Error:

    250 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command134_Click, line " & Erl & "."

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    not sure about your file paths but, send the file NOT the report:

    vFile1 = "C:\PDF Reports\Pro Forma Invoice - " & strCPON & ".pdf"
    DoCmd.OpenReport strReportname1, acPreview, "", "[SalesOrderNumber]=[Forms]![frmSalesOrders].[Form]![SalesOrderNumber]"
    90 DoCmd.OutputTo acOutputReport, strReportname1, acFormatPDF, vFile1


    vFile2 = "C:\PDF Reports\Bank Details - " & strCPON & ".pdf"
    91 DoCmd.OpenReport strReportname2, acPreview, "", "[SalesOrderNumber]=[Forms]![frmSalesOrders].[Form]![SalesOrderNumber]"
    92 DoCmd.OutputTo acOutputReport, strReportname2, acFormatPDF, vFile2




    190 .Attachments.Add vFile1
    195 .Attachments.Add vFile2

  3. #3
    Blings's Avatar
    Blings is offline Competent Performer
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    London, UK
    Posts
    125
    Thank you very much @ranman256 that fixed it.

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

Similar Threads

  1. Replies: 8
    Last Post: 04-30-2021, 08:58 AM
  2. Dynamic Data, Static fields
    By amitmm_10 in forum Import/Export Data
    Replies: 4
    Last Post: 02-01-2018, 11:06 PM
  3. Replies: 3
    Last Post: 07-03-2016, 09:29 AM
  4. Are reports static?
    By Buakaw in forum Reports
    Replies: 3
    Last Post: 03-22-2011, 10:24 AM
  5. Dynamic reports
    By amonadi in forum Reports
    Replies: 1
    Last Post: 10-29-2010, 01:32 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