By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

How to rename a report before it attaches to an email on the SendObject

anoble1
100+
P: 225
Hi,

I am curious to know if it is possible to rename a report so when I am adding the report as a .PDF attachment it will change the name to a specific text field in the report query or report recordsouce?

Here is what I have so far. When I run it the attachment name is "rptPO".

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEmail_Click()
  2.  
  3. DoCmd.SendObject acSendReport, "rptPO", acFormatPDF, , , , , , , True
  4.  
  5. End Sub
May 18 '18 #1
Share this Question
Share on Google+
4 Replies


anoble1
100+
P: 225
Found some similiar code and seemed to work after some modification. See below.

This allows the report name to be changed to a text field before it attaches to Outlook as a .PDF

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEmail_Click()
  2.  
  3. Dim sExistingReportName As String
  4. Dim sAttachmentName As String
  5.  
  6. sExistingReportName = "rptPO"
  7. sAttachmentName = txtPO.value
  8.  
  9. DoCmd.OpenReport sExistingReportName, acViewPreview, , , acHidden
  10. Reports(sExistingReportName).Caption = sAttachmentName
  11.  
  12. DoCmd.SendObject acSendReport, sExistingReportName, acFormatPDF, , , , , , , True
May 18 '18 #2

PhilOfWalton
Expert 100+
P: 1,430
If that works, well and good.

Otherwise might I suggest you investigate the Scripting.FileSystemObject which allows checking the existence of files & folders, copying, deleting and renaming them.

Phil
May 19 '18 #3

twinnyfo
Expert Mod 2.5K+
P: 3,284
Oble1,

You can also export the report directly with the particular name you want. For example if you have the name of the company in one of your fields in a recordset, and are exporting their report, simply name the report as it is exported. Then, attach that named report to your e-mail, as we have discussed before.

Hope that hepps.
May 19 '18 #4

NeoPa
Expert Mod 15k+
P: 31,494
Phil:
Otherwise might I suggest you investigate the Scripting.FileSystemObject which allows checking the existence of files & folders, copying, deleting and renaming them.
Do bear in mind that these tasks can also be handled quite easily using VBA and the standard libraries.
May 19 '18 #5

Post your reply

Sign in to post your reply or Sign up for a free account.