VBA DoCmd.SendObject (1 Viewer)

pekajo

Registered User.
Local time
Tomorrow, 01:35
Joined
Jul 25, 2011
Messages
133
Can someone give me the vba code to send a pdf file that is on my drive to email address.
Currently have below for just sending emails.
DoCmd.SendObject , acSendNoObject, , strEmailAddress, , , "Welcome to the Outreach!", mm, True

but not to sure on attaching a pdf as an attachment.
Thanks
Peter
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:35
Joined
Oct 29, 2018
Messages
21,358
Hi Peter. What is your default email client? Do you use Outlook?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:35
Joined
May 7, 2009
Messages
19,175
Code:
Public Function CreateEmailWithOutlook( _
    MessageTo As String, _
    MessageCC As String, _
    Subject As String, _
    MessageBody As String, _
    Optional AttachmentFile As Variant = Null)

    ' Define app variable and get Outlook using the "New" keyword
    Dim olApp As Object         'Outlook.Application
    Dim olMailItm As Object     'Outlook.MailItem  ' An Outlook Mail item
    Dim olFolder As Object      'Outlook.Folder
    Dim olNameSpace As Object   'Outlook.NameSpace
 
    Dim varItem As Variant

    'Set olApp = New Outlook.Application
    Set olApp = CreateObject("Outlook.Application")
    Set olNameSpace = olApp.GetNamespace("MAPI")
    Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
    ' Create a new email object
    Set olMailItm = olFolder.Items.Add(olMailItem)

    ' Add the To/Subject/Body to the message and display the message
    With olMailItm
        .To = MessageTo
        .CC = MessageCC
        .Subject = Subject
        .body = MessageBody
        ' request a readers reciept so I know the email has been read
        .ReadReceiptRequested = True
        If IsArray(AttachmentFile) Then
            For Each varItem In AttachmentFile
                .Attachments.Add varItem
            Next
        ElseIf IsNull(AttachmentFile) = False Then
            .Attachments.Add AttachmentFile
        End If
        '.Display    ' To show the email message to the user
        .Importance = olImportanceHigh
         .Send
    End With

    ' Release all object variables
    olApp.Quit
    Set olMailItm = Nothing
    Set olFolder = Nothing
    Set olNameSpace = Nothing
    Set olApp = Nothing

End Function

your code:
Code:
Call CreateEmailWithOutlook("EmailAddress","","Welcome to the Outreach!", "your message, "c:\folder\thePDF.pdf")
 

Users who are viewing this thread

Top Bottom