Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send form attachments via Outlook e-mail?

Status
Not open for further replies.

Artois27

Technical User
Nov 19, 2010
34
GB
I have a form that sends the data imputed by a user via an MS Outlook 2007 e-mail to their boss. The following code is working on the click of a command button. However, there is another form field that allows users to attach any relevant files. My question is how do I code the button to send the attachments the user has uploaded on the form as part of my outgoing e-mail? The code below is what I have at the moment.

Private Sub Command31_Click()
'Start of code
Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'Creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.Application")
DoEvents
Set objEmail = objOutlook.CreateItem(olMailItem)
DoEvents
'Creates string with email address
strEmail = boss
strBody = "The employee " & Employee_name & " on " & Date_Requested & _
" requested " & Leave_type & " leave. " & Chr(13) & Chr(13) & "Details:" & Chr(13) & Chr(13) _
& "Start date: " & Start_date & Chr(13) _
& "End date: " & End_date & Chr(13) _
& "Duration: " & Duration & Chr(13) _
& "Half day?: " & Half_day & Chr(13) _
& "Leave type: " & Leave_type & Chr(13) _
& "Contact method: " & Contact_method & Chr(13) _
& "Contact time: " & Contact_time & Chr(13) _
& "Contact person: " & Contact_person & Chr(13) _
& "Reason for sickness: " & Reason_for_sickness & Chr(13) _
& "Doctor consulted: " & Doctor_consulted & Chr(13) _

DoEvents
'Creates and sends email
With objEmail
DoEvents
.To = strEmail
DoEvents
.Subject = "New Absence Request"
DoEvents
.Body = strBody
DoEvents
.Send
End With

Set objEmail = Nothing
Exit Sub
End Sub
 
I'd use the Attachments.Add method

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes but I don't know what order the code should be in to put into my current code to get it working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top