mike60smart
Registered User.
- Local time
- Today, 01:58
- Joined
- Aug 6, 2017
- Messages
- 2,020
Hi Everyone
Can someone tell me where I an going wrong with the following Code to add an attachment to an email.
The Code creates a PDF file in the Folder as required
It displays the Report
But it does not Display the Email in Outlook ?
The code is as follows:-
I am getting the following error.
Any help appreciated
Can someone tell me where I an going wrong with the following Code to add an attachment to an email.
The Code creates a PDF file in the Folder as required
It displays the Report
But it does not Display the Email in Outlook ?
The code is as follows:-
Code:
Private Sub cmdPrint_Click()
10 On Error GoTo cmdPrint_Click_Error
20 If Me.AgentPaid = -1 Then
30 Me.PaidDate = Date
40 If Me.Dirty Then Me.Dirty = False
50 MsgBox "A Copy of the PDF will be saved to the C Drive EMails Folder", vbInformation
Dim strSQL As String
Dim outApp As Object
Dim outMail As Object
Dim strReportname As String
Dim strMailItem As String
Dim strWhere As String
Dim strToWhom As String
Dim strMsg As String
Dim strSubject As String
Dim strPath As String
60 strToWhom = Me.AgenteMailP
70 strWhere = "[ID]=" & Me.id
80 strSubject = "Settlement"
90 strReportname = "AgentSettlement"
100 strMsg = "Find attached latest Settlement Details"
110 If Dir("C:\Emails", vbDirectory) = "" Then MkDir "C:\Emails"
120 strPath = "C:\Emails\" & strReportname & "-" & Format(Date, "mmddyyyy") & "- Agent Settlement" & [LoadNumber] & ".pdf"
130 Set outApp = CreateObject("Outlook.Application")
140 Set outMail = outApp.CreateItem(0)
150 DoCmd.OpenReport "AgentSettlement", acViewPreview
160 DoCmd.OutputTo acOutputReport, "AgentSettlement", acFormatPDF, "C:\Emails\" & Format(Date, "mmddyyyy") & "- Agent Settlement" & [LoadNumber] & ".pdf", True 'True shows email before semding
170 End If
180 With outMail
190 .To = strToWhom
200 .Subject = strSubject
201 .Attachments.Add strPath
220 .Body = strMsg
230 .Display
240 End With
250 On Error GoTo 0
260 Exit Sub
cmdPrint_Click_Error:
270 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPrint_Click, line " & Erl & "."
End Sub
I am getting the following error.
Any help appreciated