Solved

Runtime 2501 in Docmd.OutputTo after PC Rebuild & Access 2013 Upgrade

Posted on 2013-05-13
4
544 Views
Last Modified: 2013-05-14
I have just rebuilt a Win7 PC and at the same time switched from Access 2010 to Access 2013. One of my databases which saves PDF files to the local machine is now throwing runtime errors.

This is the code:

                Dim mypath As String
        mypath = Environ("userprofile")
Dim pdfPath As String
        pdfPath = mypath & "\gbis-orders\GBIS Order No " & Me.orderid.Value & ".pdf"


        Dim rptName As String
        rptName = "rptSalesOrder"
        DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, pdfPath, , , , acExportQualityPrint
        MsgBox "GBIS Order No " & Me.orderid.Value & " Saved." & vbCrLf & vbCrLf & "LOCATION: " & pdfPath, vbInformation, "PDF Created."

Open in new window


The attached image shows us that the environment variable is being picked up okay too.

runtime 2501
The actual error is run-time error 2501 the OutputTo action was cancelled.

If anyone can help with this I'd be grateful!
0
Comment
4 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 39164170
Can you open the report manually (i.e. by doubleclicking it in the Nav Pane)?

If not, figure out why. Bad or malformed VBA code can cause this error. I realize it worked in other versions of Access, but it's not uncommon for code that worked fine in one version to fail in another (as the MSFT team fixes bugs and such).

Also, this could be caused by a report that has no data. You should handle that in your code, something like this:

Sub MyButton_Click
On Error Goto myError

DoCmd.OpenReport blah blah
<other code>

MyExit:
   Exit Sub

MyError:
   If Err.number <> 2501 then
       Msgbox "Error: "& err.description
   End If
     
   goto myExit

End Sub
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 250 total points
ID: 39164199
Debugging thoughts to see what might be causing this...

Try simply opening your report instead of using the ouput to command.  Does this also fail?  If so, check and make sure that you have set a default printer (this will also affect OutputTo, SendObject, etc)

Temporarily make this change:


        Dim rptName As String
        rptName = "rptSalesOrder"
        Docmd.OpenReport "rptSalesOrder", acViewPreview 
       ' DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, pdfPath, , , , acExportQualityPrint

Open in new window


If the OpenReport statement works without error, make sure that the permissions are set up properly on the folder you are trying to write the report to.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39165496
Not sure if it was mentioned or not...

...but check the obvious as well...
Make sure that the path:
Is this valid?..is valid (actually exists on the target machine and the user can access this path) and is spelled correctly.
(System paths/names, ..etc, ...may have changed when you upgraded)

You will get the exact error you state if the path/filename is invalid.
For example, when I do this:
C:\zzzzzz\suqta610\goober.pdf
I get the exact error you are getting. (because that path is invalid/does not exist)
When I give it a valid path:
C:\Temp\goober.pdf
...it works fine...

JeffCoachman
0
 

Author Closing Comment

by:Computer_Support_Norwich
ID: 39166453
Normally when I ask a question here on EE, it's because I lack the knowledge to do what I need to do. On this occasion, I have just been an idiot, so I apologise.

As soon as I opened the report manually (rather than trying to PDF it) I got a print related error, and then I realised my default and only physical printer was a tiny label printer. Needless to say, Access was giving me margin related errors.

I installed my printer again and all is good. I must have wasted hours on this!  You are all well known on EE to me and I know you are all pretty amazing on Access so I apologise for wasting your time :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now