?
Solved

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

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 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