Solved

Runtime Error 2585 (this action can't be carried out while processing a form or report event)

Posted on 2008-06-16
1
1,591 Views
Last Modified: 2013-12-05
I have a command button (cmdPurchaseOrderPrint) on my form (Orders) that opens a print dialog box for a report.  When I click 'ok' to print the form I see Error # 2585, This action can't be carried out while processing a form or report event.  Debugging reveals the offending statement is RunCommand acCmdPrint.    

Here's the code behind the click event of the command button:
DoCmd.OpenReport "PurchaseOrder", acViewPreview

And here's the code behind the on open event of the report:

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Error_Handling:

Dim cn As ADODB.Connection
Set cn = CurrentProject.Connection

Dim rstOrders As New ADODB.Recordset
Dim strSQL As String

If CurrentProject.AllForms("Orders").IsLoaded = False Then
    Dim OrderNum As String

Get_Input:
    OrderNum = InputBox("Enter Order #")
    If OrderNum <> "" Then
        strSQL = "SELECT Order_Num FROM tblOrders WHERE Order_Num = '" & OrderNum & "' "
        rstOrders.Open (strSQL), cn, adOpenForwardOnly, adLockReadOnly
        If rstOrders.EOF = True Then
            MsgBox "Order #" & OrderNum & " Not Found!", vbCritical
            rstOrders.Close
            GoTo Get_Input
        Else
            strSQL = "SELECT * FROM tblOrders WHERE Order_Num = '" & OrderNum & "' "
            Me.RecordSource = strSQL
        End If
    Else
        End
        DoCmd.Close
    End If

Else
    strSQL = "SELECT * FROM tblOrders WHERE Order_Num = " & Forms!Orders!Order_Num
    Me.RecordSource = strSQL
    RunCommand acCmdPrint    
End If

Exit Sub

Error_Handling:
If Err.Number = 2501 Then  'user canceled print dialog box
    End  
Else
    MsgBox Err.Number
    MsgBox Err.Description
End If

End Sub

Any idea what I'm doing wrong?

Thanks in advance.

0
Comment
Question by:hennessym
1 Comment
 
LVL 1

Accepted Solution

by:
hennessym earned 0 total points
Comment Utility
Solved it - the key was to put RunCommand acCmdPrint in the OnActivate event.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

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…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

12 Experts available now in Live!

Get 1:1 Help Now