Modify VBA code to send email with attachment

Tor_Fey

Registered User.
Local time
Today, 19:36
Joined
Feb 8, 2013
Messages
121
Good Afternoon all;

I need a little help with the below code:

Code:
linkString = "mailto:" & Email & "?subject=Application for " & Me.leavedays & " days " & Me.leavetype & " leave " & varme & "&body=Please approve my application for " & leavedays & " days " & leavetype & " leave for the period " & leavestart & " to " & leaveend & vbCrLf & vbCrLf & " - " & Me.applycomments & vbCrLf & vbCrLf & varme

Application.FollowHyperlink linkString

This code works fine, however i need it to attache a report to it an I am unsure how to modify the code to include an attachment, your help as always is very much appreciated.

Kind Regards
Tor Fey
 
Hi theDBguy,

Thanks so much for your reply.
I have already tried that and receive the error 2296?

Regards
Tor Fey
What is error 2296 and what did your code look like?
 
Mailto would not allow attachments (https://blog.mailtrap.io/mailto-links-explained/#Add_an_attachment), so you could try Docmd.SendObject as proposed by theDBguy, using Outlook automation if mail client is Outlook or CDO mail (https://devblogs.microsoft.com/scripting/how-can-i-attach-a-file-to-an-email-sent-using-cdo/).

Cheers,
Vlad
Morning All;

As i have said, I receive the error 2296 when i use the docmd.sendobject method, because i don't have a local install of MS Access it is a packaged version delivered via MS APP_V, Error 2296 is: "The password is invalid".

My Solution is as follows:
Code:
Private Sub EmailReport_Click()
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim fileName As string, todayDate As String   

'Export report in same folder as db with date stamp
todayDate = Format(Date, "MMDDYYYY")
fileName = Application.CurrentProject.Path & "\ApplicationReadyForComments_" & todayDate & ".pdf"
DoCmd.OutputTo acReport, "rpt_email_line", acFormatPDF, fileName, False

'Email the results of the report generated
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
    .Recipients.Add "Please Select Line Manager"
    .Subject = "Application Awaiting Line Manager Comments"
    .Body = "Comment is required as per the attached application"
    .Attachments.Add fileName
    .Display       
End With

However now i am receiving the following Error: Run-Time error '48' - Error in loading DLL.

How do i avoid this error?

Kind Regards
Tor Fey
 

Users who are viewing this thread

Back
Top Bottom