Export an Access report as a PDF with a specific name using code

Stevep4

New Member
Joined
Aug 28, 2015
Messages
34
I'm trying to export an Access report to a specific location with the file saving with a specific name that is linked to a form in the Access database. I have the below code. The problem is with the strSubject line. I'm not sure how to get the information from the form (the form is DateRanges and the filed in the form is text2). With that form, the code works. Below is the code.

Rich (BB code):
Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Private Sub Command20_Click()
Dim stReport As String
Dim stSubject As String
Dim FileNamePDF As String
strSubject = "Brooklyn" & [Forms]![dateranges]![text2]
strReport = "Store251001"
DoCmd.OpenReport strReport, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, "R:\Arcguve\" & strSubject & ".pdf"
End Sub
[/FONT]


Thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The form should be open when you use that code, otherwise there is nothing for the code to get when it gets the date from the form textbox (text2).
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top