Public Function CreateEmailWithOutlook( _
MessageTo As String, _
MessageCC As String, _
Subject As String, _
MessageBody As String, _
AttachmentFile As Variant)
' Define app variable and get Outlook using the "New" keyword
Dim olApp As New Outlook.Application
Dim olMailItm As Outlook.MailItem ' An Outlook Mail item
Dim olFolder As Outlook.Folder
Dim olNameSpace As Outlook.NameSpace
Set olApp = New Outlook.Application
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
' Create a new email object
Set olMailItm = olFolder.Items.Add(olMailItem)
' Add the To/Subject/Body to the message and display the message
With olMailItm
.To = MessageTo
.CC = MessageCC
.Subject = Subject
.Body = MessageBody
[COLOR="Red"].ReadReceiptRequested = True[/COLOR]
.Attachments.Add AttachmentFile
.Display ' To show the email message to the user
.Send
End With
' Release all object variables
Set olMailItm = Nothing
Set olFolder = Nothing
Set olNameSpace = Nothing
Set olApp = Nothing
End Function
Private Sub Command181_Click()
If MsgBox("Warning! You are about to send a LIVE JOB SHEET to a Contractor. Do you wish to continue?", vbYesNo) = vbYes Then
'click the Yes
Dim strDocName As String
Dim strPath As String
strDocName = "Report"
' save report to myDocument
strPath = SpecialFolderPath("MyDocuments") & "\"
If Dir(strPath & strDocName & ".pdf") <> "" Then Kill (strPath & strDocName & ".pdf")
' open report in print preview
DoCmd.OpenReport ReportName:=strDocName, View:=acViewPreview, WhereCondition:="[ID]=" & Me.ID
' create pdf file in mydocuments
DoCmd.OutputTo acOutputReport, strDocName, acFormatPDF, _
strPath & strDocName & ".pdf", True
'close the report
DoCmd.Close acReport, strDocName
' email this report
CreateEmailWithOutlook Me.txtone.Value & "", "info@conquerltd.com", "New Job Sheet", "Dear Trade, New Job Sheet Attached.", _
strPath & strDocName & ".pdf"
Else
'click the no
End If
End Sub