Full Version: Email Attachment from a Form
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
kappler
I need to email an attachment from an Access form
The filename and path of the attachment are held in
a field called txtPath on the the form.

At what point or where in the following code do I need to
insert a reference to the field txtPath.

This is the code:

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

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

With objOutlookMsg
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub

Any help appreciated
dannyseager
try...

Set objOutlookAttach = .Attachments.Add(me.txtPath)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.