Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time Error '2501' - The PrintOut action was canceled.

Status
Not open for further replies.

claskew

Technical User
Feb 23, 2011
21
US
Hi All,

I am here today again. Now with a print issue. I am receiving an error message that is listed in the subject. Listed below is the current code that I currently have. I know this is a quick fix, but I can not figure it out for the world.

Option Explicit

Private Sub CommandClose_Click()
DoCmd.Close acReport, "rpt_PubGeneralRecord", acSavePrompt
End Sub
Private Sub CommandPrint_Click()
Dim intLeft As Integer
Dim intTop As Integer
intTop = CommandPrint.Top
intLeft = CommandPrint.Left
[highlight]DoCmd.PrintOut , , , , 1[/highlight]
CommandPrint.Top = intTop
CommandPrint.Left = intLeft
DoEvents
End Sub
Private Sub Report_Load()
Report.Caption = "General Report for " & [Forms]![form_View]!ComboPubName.Column(1)
End Sub


Any help would be appreciated!!!!!
 
The error must be trapped in the code that opens the report. Try something like:
Code:
Private Sub CommandPrint_Click()
    On Error GoTo Err_CommandPrint_Click
    Dim intLeft As Integer
    Dim intTop As Integer
    intTop = CommandPrint.Top
    intLeft = CommandPrint.Left
    DoCmd.PrintOut , , , , 1
    CommandPrint.Top = intTop
    CommandPrint.Left = intLeft
    DoEvents
Exit_CommandPrint_Click:
    On Error Resume Next
    Exit Sub

Err_CommandPrint_Click:
    Select Case Err
       case 2501 ' openning of report canceled
       ' ignore
       Case Else
          MsgBox Err.Description
    End Select 
    Resume Exit_CommandPrint_Click
End Sub

Duane
Hook'D on Access
MS Access MVP
 
I have taken the code you suggested and yes, it immediately has removed the Run-Time Error 2501. Great! Thanks, but now it won't even print.

A Save As box appears which was appearing before, I apologize that I forgot to mention that. Behind the Save As box is the printing queue box that lets you know it is printing, but I just recently seen that it is not connected to the correct printer. How and where do I place code for it to pick up any user's default printer who uses the db and would like to print out a report?

I am attaching a view of what comes up when I press the print report button.
 
 http://www.mediafire.com/file/ifdgsuhj6dnyswz/Print.docx
I think you misunderstood what I was saying. There is a button in the report that states 'Print Report'. When the 'Print Report' button on the report in Access is clicked, the Save As box pops open with the print box grayed out behind the Save As box. What is making the Save As box appear as well as the print box is printing to the Microsoft Office printer instead of the default.

Any help is greatly appreciated.
 
You are apparently using the Print View which I never use. What is the purpose of:
Code:
 DoCmd.Close acReport, "rpt_PubGeneralRecord", [b][red]acSavePrompt[/red][/b]
I would remove the acSavePrompt.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top