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