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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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?  

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DexterFanDatabase DeveloperAuthor Commented:
I accept my own solution because it worked
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.