Hi,
I have a report that I would like to attach to an email automatically. Is that possible?
Code:
Private Sub Report_Page()
Dim DailyReport As String
DoCmd.OutputTo acOutputReport, DailyReport, _
acFormatRTF, "DailyReport.rtf", True
DoCmd.Save acReport, "DailyReport" 'this line doesn't work
Dim iMsg, cdoConfig As Object
Dim sch, As String
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2
.Item(sch & "smtpserver") = "Exchange._________.com" 'company name removed
.Item(sch & "smtpserverport") = 25
.update
End With
Set iMsg = CreateObject("CDO.Message")
With iMsg
Set .Configuration = cdoConfig
.To = "________.com" 'email removed
.CC = ""
.BCC = ""
.From = "__________.com" 'email removed
.Subject = "Weekly Training Updates"
.TextBody = "Please see the attached document for training updates"
.Addattachment "C:/" & savename 'this line doesn't work
.Send
End With
Kill "C:/" & savename 'this line doesn't work
Set iMsg = Nothing
Set cdoConfig = Nothing
DoCmd.Close acReport, "Daily Report"
End Sub
if i remove all the lines that i have commented "this line doesn't work" then the email is sent. So I know the email code works, but I can't attach my report. Any suggestions?
thanks,
teebumble