Public Sub SendeMail(myDoc As String, myBody As String, mySubject As String, myAddy As String, Optional myFile As String) ' e.g Brochure, Addy, Path.pdf
On Error GoTo Err_Send
DoCmd.Hourglass True
'// requires Outlook Object Library \\
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Set MyOutlook = New Outlook.Application
Set MyMail = MyOutlook.CreateItem(olMailItem) 'need to re-create Set each cycle.
MyMail.To = myAddy
MyMail.Subject = mySubject
Select Case myDoc
Case Is = "Brochure"
MyMail.Body = myBody
Case Else
MyMail.Body = "Good morning" & vbNewLine & vbNewLine & "Please our attachment following your recent enquiry." & _
vbNewLine & vbNewLine & "Please do not hesitate to contact us should you require any further information." & vbNewLine & vbNewLine
End Select
MyMail.Body = MyMail.Body & vbNewLine & vbNewLine & _
"Kind Regards " & vbNewLine & vbNewLine & DLookup("[User]", "Users", "UserID = '" & Environ("UserName") & "'") & _
vbNewLine & DLookup("[Company]", "Company Details") & vbNewLine & _
"tel: " & DLookup("[Telephone]", "Company Details") & vbNewLine & _
"fax: " & DLookup("[Fax]", "Company Details") & vbNewLine & _
"eMail: " & DLookup("[eMail]", "Company Details") & vbNewLine & _
"www: " & DLookup("[www]", "Company Details")
' Is there an Attachment
If Len(myFile & "") > 0 Then
MyMail.Attachments.Add myFile, olByValue, 1
End If
MyMail.Send 'This sends it in Standard Outlook
Set MyMail = Nothing
Set MyOutlook = Nothing
Exit_Send:
DoCmd.Hourglass False
Exit Sub
Err_Send:
DoCmd.Hourglass False
MsgBox err.Description, vbCritical, "eMailing_" & err.Number
Resume Exit_Send
End Sub