Closing a form error 2585 This action cannot be carried out while processing a form or report event

S

SDLittle13

Closing a form error 2585 This action cannot be carried out while
processing a form or report event.

This message is occurring in a pop-up I have created to add line items
to an invoice.

The form works fine if they create a line item and click the ITEM DONE
button which adds the item to a temporary table and then executes Call
Line_Item_Wrap_Up

This is the code executed which simply determines which module called
it, reopens that form, and closes the current form. This work fine
under normal circumstances.


Sub Line_Item_Wrap_Up()

DoCmd.SetWarnings True

If Public_CALLED_LINE_ITEM_POP_UP = "NEW INVOICE" Then
DoCmd.OpenForm "NEW INVOICE"
Else
DoCmd.OpenForm "EDIT INVOICE SHOWN"
End If
DoCmd.Close acForm, "LINE ITEM POP-UP", acSaveNo

End Sub


However, when I added a CANCEL BUTTON to allow them to simply go back
without adding a line item using the same paragraph to return control
I get the error. The code connected to this button is below. As you
can see it call the same wrap up paragraph as the code that adds the
line item, but for some reason it doesn't feel it can close the form.

Private Sub CancelButton_Enter()

Call Line_Item_Wrap_Up

End Sub

Private Sub CancelButton_Click()

Call Line_Item_Wrap_Up

End Sub

Any ideas here would be great. Thank you in advance for your help.
 
S

Stefan Hoffmann

hi,

Closing a form error 2585 This action cannot be carried out while
processing a form or report event.
Try a CancelEvent before closing your form.
Sub Line_Item_Wrap_Up()

DoCmd.SetWarnings True

If Public_CALLED_LINE_ITEM_POP_UP = "NEW INVOICE" Then
DoCmd.OpenForm "NEW INVOICE"
Else
DoCmd.OpenForm "EDIT INVOICE SHOWN"
End If DoCmd.CancleEvent
DoCmd.Close acForm, "LINE ITEM POP-UP", acSaveNo

End Sub
Private Sub CancelButton_Enter()
Call Line_Item_Wrap_Up
End Sub
What do you like to achive with the enter event?


mfG
--> stefan <--
 
S

SDL

On the enter or click even I just want to close the pop up and return
to the form that opened it. I tried the cancelevent, but it did not
fix the problem I still get the same error.
 
S

Stefan Hoffmann

hi,
On the enter or click even I just want to close the pop up and return
to the form that opened it.
I tried the cancelevent, but it did not fix the problem I still get the same error.
Just delete the on enter method of your button. I cannot imagine any
reason for calling Line_Item_Wrap_Up in it.

btw, you should use a better naming convention, e.g.:

--
Option Compare Database
Option Explicit

Private m_CalledLineItemPopUp As String

Private Sub LineItemWrapUp()

DoCmd.SetWarnings True

If m_CalledLineItemPopUp = "NEW INVOICE" Then
DoCmd.OpenForm "InvoiceNew"
Else
DoCmd.OpenForm "InvoceEdit"
End If
DoEvents
DoCmd.Close acForm, "LineItemPopUp", acSaveNo

End Sub

Private Sub cmdCancel_Click()

LineItemWrapUp

End Sub

Private Sub cmdCancel_Enter()

LineItemWrapUp

End Sub

Private Sub Form_Open(Cancel As Integer)

m_CalledLineItemPopUp = "NEW INVOICE"

End Sub
 
S

SDL

Dropping the enter proceeder did the trick. Thank you for the pointers
on the naming conventions I have programmed for years and tend to use
an older style, but I can see your point. Thank you for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top