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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,223,099
Messages
6,170,111
Members
452,302
Latest member
TaMere

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