Access 2010 error 2501

I am using the following vba statement:

DoCmd.OutputTo acOutputReport, RepName, acFormatPDF, FileLocation, False, "", 0, acExportQualityPrint

to create a pdf file of a report.  It works well in Access 2007 but not in 2010.  I get an error code 2501.  All I want is a pdf file of a report, generated in VBA.  What can I do?

DexterFanDatabase DeveloperAsked:
Who is Participating?
DexterFanDatabase DeveloperAuthor Commented:
After much trial and error and some internet searching I tried the Access 2010 macro "ExportwithFormatting".  Conversion of this macro to vba gave me the appropriate code.  After adapting the syntax to my situation, I ended up with:

DoCmd.OutputTo acOutputReport, RepName, "PDFFormat(*.pdf)", FileLocation, False, "", , acExportQualityPrint

Even with this, I kept getting the 2501 error until I had the correct string in the FileLocation variable.
Once that was done, I was able to successfully create a pdf file where I wanted it and with the title I wanted.  Spaces and dashes in the FileLocation string did not matter as long as everything was correct for my file-folder structure.

Thanks to mbizup for trying to help me.
A couple of things to check

- Do other Export formats work?
- Do you have a default printer set on your Access 2010 machine?  Opening, mailing or exporting reports may fail with this error (even if you are not actually printing them).
DexterFanDatabase DeveloperAuthor Commented:
Thanks.  Good questions.  I'll check them out and get back to you.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DexterFanDatabase DeveloperAuthor Commented:
There is a default printer set on the Access 2010 machine.  I tried other export formats (rtf, html) and got an error 2304 message that "Microsoft Access can't save output data to the specified file".  I used defined variables to determine my file name.

Filepath = "c:\access 2010\TestRep_"
RepDate = me!PublicationDate       (where me!pulicationdate = 2011-12-08)
PubName = Me!PublicationName    (where Me!PublicationName  = "Metro News"

FileLocation = FilePath & PubName & RepDate & ".rtf"

RepName = "RepMetroNewsNightlyReport"

DoCmd.OutputTo acOutputReport, RepName, acFormatRTF, FileLocation, False, "", 0, acExportQualityPrint

I still got an error.  

I tried everything with acFormatPDF and still got the 2501 error

These routines worked on my home computer with both Access 2007 and 2010.  They are not working on a corporate networked computer.

I am able to view a report and use ribbon commands to successfully output the report to PDF and RTF and HTML, so write permissions are not an issue.  

Does anyone have a solution?  

Double check that you can actually write a file to the file location that you are specifying in the code.

The file your code is currently trying to write is:

c:\access 2010\TestRep_Metro News2011-12-08.rtf

Make sure that it is what you are expecting, that the folder exists and that you have permissions to write to it.

The space/special characters in your path may be problematic using an Access export.

Also try renaming your report/publication name to  "MetroNews" (with no space), and removing the space in the "access 2010" part of the path so that the target file would be:


And possibly use underscores instead of  dashes:


DexterFanDatabase DeveloperAuthor Commented:
Thanks for your ideas.  However, the goal is to write to a pdf file.  I don't understand why the code works on one computer with spaces and dashes in the name, and not on another.  I don't understand why I can write to a pdf file from the Print Preview ribbon but not through code.  Does anyone know code to mimic the ribbon commands from Print Preview?
DexterFanDatabase DeveloperAuthor Commented:
I accept my own solution because it worked
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.