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,625 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
ID: 21795351
Solved it - the key was to put RunCommand acCmdPrint in the OnActivate event.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

861 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