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
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