Solved

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

Posted on 2013-05-13
4
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

730 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