The Close action was canceled. Run Time error '2501' (1 Viewer)

Local time
Today, 01:30
Joined
Oct 7, 2016
Messages
43
Dear Sir,

In MsAccess 2007 I have two Forms, Form1 and Form2

The code written :-

Dim stDocName As String
Dim stLinkCriteria As String

DoCmd.Close acForm, "Form1"
stDocName = "Form2"
DoCmd.OpenForm stDocName, , , stLinkCriteria


I have also used the following syntax :-
(1) before above code [ Docmd.SetWarning False ] and after Code [Docmd.SetWarning True]
(2) Error Handler


While Closing Form1 and Opening Form2 , I am getting an Error The Close action was canceled.
Run Time error '2501'


Note : In the above mentioned process I do not want to Save Form1 and Form2.

Kindly solve my issue.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:30
Joined
May 7, 2009
Messages
19,247
can you open Form2 first before you close Form1?
meaning change the order of your code.
 
Local time
Today, 01:30
Joined
Oct 7, 2016
Messages
43
can you open Form2 first before you close Form1?
meaning change the order of your code.

As Suggested , I have changed the code , still the same error received.

Syntax as follows :

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, "Form1"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:30
Joined
May 7, 2009
Messages
19,247
do you have other codes inside form1 coz i tried it.
 

Attachments

  • OpenCloseForm.accdb
    412 KB · Views: 409

Gasman

Enthusiastic Amateur
Local time
Today, 09:30
Joined
Sep 21, 2011
Messages
14,343
Is that because you are trying to close a form in the close event?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:30
Joined
May 7, 2009
Messages
19,247
Gasman is correct, you are doubly-closing the form.
see this change on the airline_mast form.
 

Attachments

  • Err_Open_Close.accdb
    444 KB · Views: 346

Users who are viewing this thread

Top Bottom