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

Stevep4

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

Some videos you may like

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.

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,690
Office Version
  1. 2013
Platform
  1. Windows
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).
 

Watch MrExcel Video

Forum statistics

Threads
1,109,054
Messages
5,526,510
Members
409,705
Latest member
MB1984

This Week's Hot Topics

Top