The OutputTo action was canceled 2501

Hello1

Registered User.
Local time
Today, 13:45
Joined
May 17, 2015
Messages
271
I cant get to export my report as PDF with the OutputTo command.
First I was getting another error that it was not supported if I remember right and found out an add on which has to be installed from microsofts wibsite.
https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=7

After that Im getting the error in the title.
This is my code
Code:
Dim FileName As String
Dim FilePath As String

FileName = Me.cboBox1.Value
FilePath = " D:\PDF\" & FileName & ".pdf"

DoCmd.OpenReport "rptReport1", acViewPreview, , , acHidden
DoCmd.OutputTo acOutputReport, "rptReport1", acFormatPDF, FilePath

'From immediate window
?FilePath
 D:\PDF\MGI.pdf

First I tried without DoCmd.OpenReport but same thing, now with it also.
If I remove the FilePath I get the popup window and can save the PDF normally. So I did next..

Code:
DoCmd.OutputTo acOutputReport, "rptReport1", acFormatPDF, "D:\PDF\MGI.pdf"
And this works just fine. I tried with manually setting FileName = "MGI" and FileName = Me.cboBox1 but same thing it doesnt want to work from a variable. :confused: :banghead:
 
Don't know if will cause issue but code shows a space in front of D in the FilePath expression.
 
:o :o
That was it, darn how I miss those simplest things :banghead:
A sharp eye u have :)
Thanks!
 
Good catch, June7. Spaces in filenames count because, unfortunately, they are legal. E.g. "C:/Documents and Settings/" as a path used to be absolutely valid.
 

Users who are viewing this thread

Back
Top Bottom