Morning all,
I'm trying to create a button that will on the onClick open up a new Outlook email with subject of Despatch | SO " & [SalesOrderNumber] and with a body of "Despatch Notification".
Please can someone suggest code?
Code:
Private Sub cmdEmailProduction_Click()10 On Error GoTo cmdEmailProduction_Click_Error
20 If Me.Dirty Then Me.Dirty = False
'30 MsgBox "A Copy of the Production Order was saved to the Production Order Folder", vbInformation
Dim strSQL As String
Dim OutApp As Object
Dim OutMail As Object
Dim strToSQL As String
Dim strSalesOrderNumber As String
Dim strSubject As String
Dim strMessage As String
Dim strReportname As String
Dim strPath As String
35 strSalesOrderNumber = Me.SalesOrderNumber
40 strToSQL = Me.txtEmail
50 strSubject = "Despatch | SO " & [SalesOrderNumber] & ""
60 strReportname = "rptSalesOrderProduction"
70 strPath = "\\LUCREZIA-NOBLE\Database\ProductionOrders\" & "Production Order " & strSalesOrderNumber & ".pdf"
80 DoCmd.OpenReport strReportname, acPreview, "", "[SalesOrderNumber]=[Forms]![frmSalesOrders].[Form]![SalesOrderNumber]"
90 DoCmd.OutputTo acOutputReport, strReportname, acFormatPDF, "\\LUCREZIA-NOBLE\Database\ProductionOrders\" & "Production Order " & strSalesOrderNumber & ".pdf"
100 strMessage = "Despatch Notification."
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 strPath
200 .Body = strMessage
210 .Display
220 End With
230 On Error GoTo 0
240 Exit Sub
cmdEmailProduction_Click_Error:
250 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdEmailProduction_Click, line " & Erl & "."
End Sub