export report pdf to specific folder with variable file name

sadiq92

Member
Local time
Tomorrow, 01:15
Joined
Jun 4, 2020
Messages
30
Hello

I have one report linked to specific record in form by using "tempvar" property which is applied to a button on the form. So when I click on the button I will get report for that record only not all the records. When report is opened , There is an other button that will export the report in pdf format.

The problem is that the file name of the report is fixed (title of the report). Can I make the report title dependent on specific field of report ?

Also, is there a way to save the report automatically in specific folder path.
 
Hi. There should be a "Filename" argument to the method you're using. You should be able to use it to designate the correct filename you want.
 
Hi. There should be a "Filename" argument to the method you're using. You should be able to use it to designate the correct filename you want.
Can you explain further please?
 
To make things clear.

The report has approval number field. So, each record has different approval number.
How I make the file name of the report( in pdf) to be the “ approval number “ .
 
What method are you using - DoCmd.OutputTo ? Button to export is where?

Post your code.
 
What method are you using - DoCmd.OutputTo ? Button to export is where?

Post your code.

Hello

The button are on the report itself.So, after the report is opened , I clicked on the button then I have to name it manually with the approval number and I have to select the folder where it to be saved manually as well.

I did not use VBA code. I use Macro Builder specifically " ExportWithFormatting" then I choosed outputfile to be pdf.
 
Hello

The button are on the report itself.So, after the report is opened , I clicked on the button then I have to name it manually with the approval number and I have to select the folder where it to be saved manually as well.

I did not use VBA code. I use Macro Builder specifically " ExportWithFormatting" then I choosed outputfile to be pdf.
Hi. Here's a screenshot of the macro builder. I am referring to the highlighted area in red. Try using your TempVars in there.

export.png
 
so, I meant I choose output format to be pdf not output file.

what shall I write on output file?
Hi. I was only showing your the basic macro action. I didn't fill the boxes out, because you should already have yours filled out. For the Output Format, yes, you should select PDF. For the Output File, you need to enter the filespec you want to use. This includes the file path and the file's name. For the name, you can use your TempVars (assuming it contains the name you want to use).
 
Hi. I was only showing your the basic macro action. I didn't fill the boxes out, because you should already have yours filled out. For the Output Format, yes, you should select PDF. For the Output File, you need to enter the filespec you want to use. This includes the file path and the file's name. For the name, you can use your TempVars (assuming it contains the name you want to use).

This is the macro of the form button that open the report of the specific record.
2525.JPG
 
Try:

"C:\Users\user\Documents\Applications\" & Forms!formname!fieldname & ".pdf"

or

"C:\Users\user\Documents\Applications\" & TempVars!ApprovalEx & ".pdf"
 
Try:

"C:\Users\user\Documents\Applications\" & Forms!formname!fieldname & ".pdf"

or

"C:\Users\user\Documents\Applications\" & TempVars!ApprovalEx & ".pdf"
And don't forget, you may have to add the equal sign up front. Cheers!
 
Try:

"C:\Users\user\Documents\Applications\" & Forms!formname!fieldname & ".pdf"

or

"C:\Users\user\Documents\Applications\" & TempVars!ApprovalEx & ".pdf"

Perfect.

However, I have small problem . The approval number is autonumber with format . The format is "2020-EXP-"0000 . So, if it 196. The number will show on report like "2020-EXP-"0196". However, when saved it will save as 196.

How I make the file name to be including the format.
 
Use Format function.

Format(TempVars!ApprovalEx, "2020-EXP-0000")

However, will have to modify code next year. Should probably look at making year part dynamic.

Year(Date()) & "-EXP-" & Format(TempVars!ApprovalEx, "0000")
 
Use Format function.

Format(TempVars!ApprovalEx, "2020-EXP-0000")

However, will have to modify code next year. Should probably look at making year part dynamic.

Year(Date()) & "-EXP-" & Format(TempVars!ApprovalEx, "0000")

Thank you June7

One last help if it is possible . If I want to add new button but instead of saving report in specified folder , I want to attach the report pdf automatically in new email message. I know "EmailDatebaseObject" macro can do that . However, I want the file name on attached email to be the approval number (same with pdf exporting button). How I can do this ?
 
That would require VBA Outlook automation code. Report PDF must first be saved to folder (which you already do) then attach to email Attachment property. Very common topic.
 

Users who are viewing this thread

Back
Top Bottom