The following code I use to send email with a report as an attachment. But it gives the error message "Cannot find the file, Verify the path & file name are correct"
I checked file name (LETTEREMAI) is correct. Please help me to solve the issue.
Private Sub Command29_Click()
Dim emailTo As String
Dim emailCc As String
Dim emailSubject As String
Dim emailText As String
Dim fileName As String
Dim outApp As New Outlook.Application
Dim outMail As Outlook.MailItem
Dim outlookStarted As Boolean
On Error Resume Next
Set outApp = GetObject("Outlook.Application")
On Error GoTo 0
If outApp Is Nothing Then
Set outApp = CreateObject("Outlook.Application")
outlookStarted = True
End If
emailTo = Me.SD_EMAIL 'active form data
emailCc = Me.SD_CCEM 'active form data
emailSubject = "Renewal of Service Agreement -" & Me.S_RNO 'active form data
emailText = "Dear Sir" & vbCrLf & vbCrLf & _
"Please refer the letter is attached herewith" & vbCrLf & vbCrLf & _
"Regards" & vbCrLf & _
"Purchasing Division"
fileName = "Service Agreement-" & Me.S_RNO & ""
DoCmd.OutputTo acReport, "LETTEREMAIL", acFormatPDF, fileName, False
Set outMail = outApp.CreateItem(olMailItem)
outMail.To = emailTo
outMail.Subject = emailSubject
outMail.Body = emailText
outMail.Attachments.Add fileName
outMail.Send
If outlookStarted Then
outApp.Quit
End If
Set outMail = Nothing
Set outApp = Nothing
End Sub
I checked file name (LETTEREMAI) is correct. Please help me to solve the issue.
Private Sub Command29_Click()
Dim emailTo As String
Dim emailCc As String
Dim emailSubject As String
Dim emailText As String
Dim fileName As String
Dim outApp As New Outlook.Application
Dim outMail As Outlook.MailItem
Dim outlookStarted As Boolean
On Error Resume Next
Set outApp = GetObject("Outlook.Application")
On Error GoTo 0
If outApp Is Nothing Then
Set outApp = CreateObject("Outlook.Application")
outlookStarted = True
End If
emailTo = Me.SD_EMAIL 'active form data
emailCc = Me.SD_CCEM 'active form data
emailSubject = "Renewal of Service Agreement -" & Me.S_RNO 'active form data
emailText = "Dear Sir" & vbCrLf & vbCrLf & _
"Please refer the letter is attached herewith" & vbCrLf & vbCrLf & _
"Regards" & vbCrLf & _
"Purchasing Division"
fileName = "Service Agreement-" & Me.S_RNO & ""
DoCmd.OutputTo acReport, "LETTEREMAIL", acFormatPDF, fileName, False
Set outMail = outApp.CreateItem(olMailItem)
outMail.To = emailTo
outMail.Subject = emailSubject
outMail.Body = emailText
outMail.Attachments.Add fileName
outMail.Send
If outlookStarted Then
outApp.Quit
End If
Set outMail = Nothing
Set outApp = Nothing
End Sub