Email an Attachment in a Table

Elwood

Four Fried Chickens
Local time
Yesterday, 23:01
Joined
Jul 13, 2004
Messages
5
I have an attachment field in my table where PDF files are stored. Is it possible set a button up to email the stored attachment using a macro or maybe some code behind a button?
This is code I used to email a report as a PDF.
Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click
Dim stDocName As String
Dim stMsg As String
‘Dim stAddress As String
Dim stSubject As String
stMsg = "See Attachment"
stDocName = "rptBoloMain"
‘stAddress = Emil@mail
stSubject = "Requested File”

DoCmd.OpenReport stDocName, acPreview, , "[ID]=" & Me![ID]
DoCmd.SendObject acSendReport, stDocName, acFormatPDF, stAddress, , , stSubject, stMsg, True
Exit_Command95_Click:
Exit Sub
Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click
End Sub
 
MyMail will do this. Sample code, below, uses variables to find the correct attachment but you can just hard code the path and name if it is not different every time.
Code:
    'Create variable for Outlook Mail
    Dim MyOutlook As Outlook.Application                'An Outlook Application
    Dim MyMail As Outlook.MailItem                      'An Outlook Mail Item
    
        'Open Outlook
    Set MyOutlook = New Outlook.Application
    Set MyMail = MyOutlook.CreateItem(olMailItem)
    
    MyMail.To = varTo
    MyMail.CC = "Loans"
    MyMail.Subject = stSubject
    MyMail.Body = stText
    MyMail.Attachments.Add "W:\Attachments\" & FullName & " Full Statement " & TeamMember & ".pdf", olByValue, 1, "All Statements"
    MyMail.Importance = olImportanceLow
    MyMail.Send
    
    Set MyOutlook = Nothing
    Set MyMail = Nothing
 
Here is a DoCmd example.
Code:
DoCmd.SendObject acSendReport, "Rpt1PageApplication", acFormatPDF, varTo, "Loans", , stSubject, stText, -1
The attachment is Rpt1PageApplication
 

Users who are viewing this thread

Back
Top Bottom