Hello All ...
I'm pretty sure this is super simple and I'm overlooking something pretty obvious ...
I did search the forum, because I'm also pretty sure this is a common questions, but I couldn't find what I was looking for
I have a bunch of buttons that, when clicked, send a report to PDF. These are all based on saved exports, which means that i have to update the path in the saved export. I'd rather not do that.
This is an annual database, so each year, the database is copied into a new folder that is named for the year. That's why the path changes each year.
I have a sub-routine that will do exactly what I need ... but I then have to copy the sub-routine to each command button and change the file name and report name.
I was hoping I could have a sub with those mechanics and then for the button, i could just define the file name and report name and then call the sub with the mechanics and have it run.
But ... it doesn't work ... why not?
The code behind the button ...
My "mechanics" code ...Code:Private Sub cmdTrpsNum_Click()' Saves the Troops by Number report as a PDF. Dim FileName As String Dim ReportName As String FileName = "Troops by Number" ReportName = "FullTroop Report" Call Export2PDF End Sub
How do i send the file name and report name from the first to the second?Code:Sub Export2PDF() Dim strPath As String Dim strDate As String Dim FullFileName As String Dim FileName As String Dim ReportName As String 'find the directory to use based on the location of the database file strPath = CurrentProject.Path & "\" 'Build file name for the report. It will be in the format: path\filename FullFileName = strPath & FileName DoCmd.OpenReport ReportName, acViewPreview 'Send the report to PDF and close the PDF file DoCmd.OutputTo acOutputReport, , acFormatPDF, FullFileName & ".pdf", False 'Close the report and don't save it DoCmd.Close acReport, ReportName, acSaveNo End Sub
My hope is to then have several (maybe six) of the smaller code ... each button would have a different file name and report name .... and just the one larger code ...
Thanks!
Susie
Kansas