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

Stevep4

New Member
Joined
Aug 28, 2015
Messages
35
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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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