Attache to email from attachment Field

theinviter

Registered User.
Local time
Yesterday, 16:56
Joined
Aug 14, 2014
Messages
262
Dears:
I Have a form and used attaches the report to "Signed_Form). so want to create a button to
1- Open email
2- Attache the File from "Signed_Form".

is there a way to do that.

as i tried below but got error message "Object does not support this property"

Private Sub Command297_Click()

Dim objOutlook As Object
Dim objMail As Object
Dim strAttachmentPath As String

On Error GoTo ErrorHandler

If IsNull(Me.Sigend_Form) Or Me.Sigend_Form = "" Then
MsgBox "Please attach a signed form before sending.", vbExclamation
Exit Sub
End If

strAttachmentPath = Me.Sigend_Form

' **Crucial Debugging:**
Debug.Print "Attachment Path: " & strAttachmentPath

' Check if file exists.
If Dir(strAttachmentPath) = "" Then
MsgBox "File not found: " & strAttachmentPath, vbCritical
Exit Sub
End If

Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)

With objMail
.To = "recipient@example.com"
.Subject = "Signed Form Attachment"
.Body = "Please find the signed form attached."
.Attachments.Add strAttachmentPath
.Display
End With

Set objMail = Nothing
Set objOutlook = Nothing

Exit Sub

ErrorHandler:
Debug.Print "Error Number: " & Err.Number
Debug.Print "Error Description: " & Err.Description
If Not objOutlook Is Nothing Then Debug.Print "objOutlook type: " & TypeName(objOutlook)
If Not objMail Is Nothing Then Debug.Print "objMail type: " & TypeName(objMail)

MsgBox "An error occurred: " & Err.Description, vbCritical
If Not objMail Is Nothing Then Set objMail = Nothing
If Not objOutlook Is Nothing Then Set objOutlook = Nothing
End Sub
 
This should be simple if you extract the attachment first using the SaveToFile method before attaching it to Outlook.
 

Users who are viewing this thread

Back
Top Bottom