Sent report as pdf file and change its name (1 Viewer)

JPR

Registered User.
Local time
Yesterday, 21:29
Joined
Jan 23, 2009
Messages
192
Hello,

I am trying to change the name of my report before sending it as attachment by email.

DoCmd.SendObject acReport, "Myreport", "PDFFormat(*.pdf)", "", "", "", "For your Info: " & Forms![frmMain]!LastName & " - " & Forms![frmMain]!FirstName, "Your action is required. Thank you", False, ""

As indicated in the subject line of the email, I would also like to name the report with values in the two textboxes, LastName and FirstName.

Thank you for your help.
 

Minty

AWF VIP
Local time
Today, 05:29
Joined
Jul 26, 2013
Messages
10,371
You can't do want you want in one command line, unfortunately.
You will have to save the file with a specific name then attach it to an email, as the sendobject method always uses the report name as the attachment name.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:29
Joined
Oct 29, 2018
Messages
21,467
Hi JPR. What you could try is open the report in preview mode but hidden. Then, change its Caption property using the Textbox value before using the SendObject method. Don't forget to close the report after the email is sent.
 

JPR

Registered User.
Local time
Yesterday, 21:29
Joined
Jan 23, 2009
Messages
192
Thanks you. I like the idea but honestly would not know how to write this code. Or should I use a macro?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:29
Joined
May 7, 2009
Messages
19,233
you can also Copy the report Myreport to the Firstname Lastname:

Dim strNewReport As String
strNewReport = Forms![frmMain]!LastName & " - " & Forms![frmMain]!FirstName
DoCmd.CopyObject strNewReport, acReport, "Myreport"

DoCmd.SendObject acReport, strNewReport, "PDFFormat(*.pdf)", "", "", "", "For your Info: " & strNewReport, "Your action is required. Thank you", False, ""

'delete it later
DoCmd.DeleteObject acReport, strNewReport
 

Users who are viewing this thread

Top Bottom