Hi June7
For those of you who would like Access to sendout an e-mail with an attached pdf file, where the file has been given as unique name. Here is how to do it!
This code opens the report, renames it and export it to you mail client. Press the send button and the mail is send and the report closes.
There wouldl be promted for send or if you change
DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", stEmail, , , stSubject, stEmailMessage, True,
To False
You will be promted for Allow or Disallow security warning.
Code:
Private Sub E_Mail_Ordre_Click()
On Error GoTo Err_Send_bestilling_Click
Dim stReport As String
Dim stWhere As String
Dim stEmail As String
Dim stSubject As String
Dim stEmailMessage As String
Dim ReportCap As String
stEmailMessage = "Message goes here." & vbCrLf & vbCrLf & "Best Regards" & vbCrLf & "Sender." 'E-mail body
stSubject = "Subject goes here: " & [Ordre_Hoved_Id] 'Email Subject
stReport = "Sparepart_Return_Order" 'Original name of the Report
ReportCap = "Spare parts return" 'Current Report Caption
stEmail = "e-mail@e-mail.xx" 'E-mail adresses or (Me.E-mail fieldname)
DoCmd.OpenReport stReport, acViewPreview, "", stWhere, acWindowNormal, "" 'Opens the report
Reports!Sparepart_Return_Order.Caption = "Output filename:" & [Ordre_Hoved_Id] 'Renames the Report
DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", stEmail, , , stSubject, stEmailMessage, True, "" 'Send out the E-mail
DoCmd.Close acReport, stReport, acSaveNo
Exit_Send_bestilling_Click:
Exit Sub
Err_Send_bestilling_Click:
MsgBox Err.Description
Resume Exit_Send_bestilling_Click
End Sub