Hello All,
So I recently wanted to know how I could save an access report, as a PDF, to my computer's desktop at the push of a button...and I did, also got it to add today's date as well. After searching the internet I found the below code and it works great, here is the code I use:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim stDocName As String
Dim stReportPathName As String
stDocName = "Sales Report By Area"
stReportPathName = "C:\Users\" & Environ("UserName") & "\Desktop\Sales Report By Area " & Format(Date, "mm-dd-yyyy") & ".pdf"
DoCmd.OpenReport stDocName, acViewPreview, , acHidden
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, stReportPathName, , True
DoCmd.Close acReport, "Sales Report By Area", acSaveNo
MsgBox "Report has been saved to Desktop"
Exit_Command2_Click:
Exit Sub
Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------
So now that I got that down I want to be able to do one more thing. I have some reports that based on a combobox selection I make will then run the report and spit out the results. I want to be able to do the exact same thing with those reports but also put the selection that I made (from my combobox) in the report name when it's saved to my desktop.
For example, let's say I go to my form and select the area that I want from the combobox....let's say I select "Northwest"....How would I get my selection of "Northwest" to fall into the report name/date (like was done in code above) so it would automatically all be one title like:
Sales Report By Area - Northwest 12-15-14
What would I need to add to the above code to make that happen?
Thanks,
Eric