AThom10731
IS-IT--Management
On form open I have code that I want to send a report as an email attachment each time the form is opened. The below code runs correctly and builds the email and attachment only it sends duplicate copy of the email each time I run it.
Please help!!!
Ann
Private Sub Form_Load()
Dim outputFName As String
Dim the_date As String
the_date = Format(Date, "mm-dd-yy")
outputFName = "\\server-01\reports\Reg1_ATO_Tracker" & the_date & ".pdf"
DoCmd.OutputTo acOutputReport, "Reg1_ATO Report by Facility", acFormatPDF, outputFName, False, , , acExportQualityPrint
Call SendMessage(0, outputFName)
DoCmd.Quit
End Sub
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim crlf As String
Let crlf = "Chr$(10) + Chr$(32) ' carriage return and line feed"
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("yourname@yourprovider.com")
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("ccname@yourprovider.com ")
objOutlookRecip.Type = olCC
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "The attached report is a listing of potential plans requiring attention as they have expired or will be expiring in the near future." & vbCrLf & vbCrLf & "SSP Database Administrator" & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Save
End With
objOutlookMsg.Send
objOutlook.Quit
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
Please help!!!
Ann
Private Sub Form_Load()
Dim outputFName As String
Dim the_date As String
the_date = Format(Date, "mm-dd-yy")
outputFName = "\\server-01\reports\Reg1_ATO_Tracker" & the_date & ".pdf"
DoCmd.OutputTo acOutputReport, "Reg1_ATO Report by Facility", acFormatPDF, outputFName, False, , , acExportQualityPrint
Call SendMessage(0, outputFName)
DoCmd.Quit
End Sub
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim crlf As String
Let crlf = "Chr$(10) + Chr$(32) ' carriage return and line feed"
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("yourname@yourprovider.com")
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("ccname@yourprovider.com ")
objOutlookRecip.Type = olCC
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "The attached report is a listing of potential plans requiring attention as they have expired or will be expiring in the near future." & vbCrLf & vbCrLf & "SSP Database Administrator" & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Save
End With
objOutlookMsg.Send
objOutlook.Quit
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub