Saving report to pdf fails with error 2501 "The OutputTo action was canceled"
Hello,
I am trying to put a "Open as PDF" button in a report's header, so that users can share the report as a pdf.
I hide the ribbon from users, so it needs to be done as a button with vba.
Every time I try to run it , I get the Error 2501 The OutputTo action was canceled message.
A quick google reveals that a fair number of people have had the same issue, but I haven't yet seen a solution that works.
I am using Access 2016 on Windows 10.
The code on my button is as follows:
As you can see I wondered if using an environment variable was the problem. It wasn't, even using the full path gives the same error message.
(TheCurrentUserName() is a function that returns the current windows logon user name.)
I can save the report as a pdf using the export to pdf option the export section of the External Data menu on the ribbon, and I can save it to the specified directory.
It also exports to Excel fine using vba. I might give in and tell them it's either print or Excel.
Any solutions?
Hello,
I am trying to put a "Open as PDF" button in a report's header, so that users can share the report as a pdf.
I hide the ribbon from users, so it needs to be done as a button with vba.
Every time I try to run it , I get the Error 2501 The OutputTo action was canceled message.
A quick google reveals that a fair number of people have had the same issue, but I haven't yet seen a solution that works.
I am using Access 2016 on Windows 10.
The code on my button is as follows:
Code:
Private Sub btnPDF_Click()
Dim exportpath As String
'exportpath = "%APPDATA%\EDB\ToDoList.pdf"
exportpath = "C:\Users\" & TheCurrentUserName() & "\AppData\Roaming\EDB"
DoCmd.OutputTo acOutputReport, , acFormatPDF, exportpath
End Sub
As you can see I wondered if using an environment variable was the problem. It wasn't, even using the full path gives the same error message.
(TheCurrentUserName() is a function that returns the current windows logon user name.)
I can save the report as a pdf using the export to pdf option the export section of the External Data menu on the ribbon, and I can save it to the specified directory.
It also exports to Excel fine using vba. I might give in and tell them it's either print or Excel.
Any solutions?