Using stored filepath to attach file to email. (1 Viewer)

firestorm998

Registered User.
Local time
Today, 06:49
Joined
Nov 28, 2006
Messages
24
I've got as far as the below basic code to send an email from my DB but am struggling to figure out how to define/add/use the filepath of a PDF doc that I store in a field called 'DOCS1' so that it can add it as the attachement to the email:

Private Sub Command18_Click()

Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object


Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.CreateItem(0)
With oMail
.To = "someone@email.com"
.Body = "Attached is a PDF file for your viewing"
.Subject = [Form_Master Form]![Description]
'.Attachments.Add ??????????????


.Display

End With

Set oMail = Nothing
Set oLook = Nothing
End Sub


Any directions thankfully received!
 

wazz

Super Moderator
Local time
Today, 21:49
Joined
Jun 29, 2004
Messages
1,711
here are some excerpts and variations you can try:
Code:
...
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookAttachment As Outlook.Attachment
    Dim varAttachmentPath as Variant
...
    varAttachmentPath = ...

' Create the e-mail message.
            Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

            With objOutlookMsg
                'Add the recipient's email address to the e-mail message.
                .To = ...

                ' Set the Subject and the Body.
                .Subject = ...
                .Body = ...
            
                'Add the attachment to the e-mail message.
                 Set objOutlookAttachment = .Attachments.Add(varAttachmentPath)
 ...
 

Users who are viewing this thread

Top Bottom