Solved

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

Posted on 2013-05-13
4
546 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

932 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

13 Experts available now in Live!

Get 1:1 Help Now