?
Solved

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

Posted on 2013-05-13
4
Medium Priority
?
556 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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

862 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