Close form error (1 Viewer)

Gismo

Registered User.
Local time
Today, 18:03
Joined
Jun 12, 2017
Messages
1,298
Hi,

i used below code to close a for if no record
I get a run time error 2585, This action can't be carried out while processing a form...
any reason why?

Code Tags Added by UG
Please use Code Tags when posting VBA Code

Please feel free to Remove this Comment
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/

Code:
Private Sub Form_Current()
    If Me.Recordset.RecordCount = 0 Then
        DoCmd.Close acForm, "admin", asSaveYes
        MsgBox "You do not have access to Admin", vbOKOnly, "Admin / Setup"
    End If
End Sub
 
Last edited by a moderator:

Ranman256

Well-known member
Local time
Today, 11:03
Joined
Apr 9, 2015
Messages
4,339
You didn't say which line gave the error,
But I would put the MsgBox first,befor form close.
Once the form closes,the code vanishes too.

You can also put ON ERROR RÉSUMÉ NEXT, as the 1st line of code to ignore the error.
 

Gismo

Registered User.
Local time
Today, 18:03
Joined
Jun 12, 2017
Messages
1,298
You didn't say which line gave the error,
But I would put the MsgBox first,befor form close.
Once the form closes,the code vanishes too.

You can also put ON ERROR RÉSUMÉ NEXT, as the 1st line of code to ignore the error.
Sorry, the DoCmd close form gives error
 

June7

AWF VIP
Local time
Today, 07:03
Joined
Mar 9, 2014
Messages
5,463
Why is form even open if you don't want it open without a record? Validate there is data before opening form.

There is no parameter of asSaveYes, there is acSaveYes. In my test, this typing error generates a variable not defined error.
AFAIK, this parameter really only works to save design edits from Design View.

Code following DoCmd.Close can still execute. Form and its controls and data will no longer be available.
 
Last edited:

Gismo

Registered User.
Local time
Today, 18:03
Joined
Jun 12, 2017
Messages
1,298
Why is form even open if you don't want it open without a record? Validate there is data before opening form.

There is no parameter of asSaveYes, there is acSaveYes. In my test, this typing error generates a variable not defined error.
AFAIK, this parameter really only works to save design edits from Design View.

Code such as MsgBox or Debug following DoCmd.Close can still execute. Form and its controls and data will no longer be available.
Not sure where the asSaveYes comes from, i used acSaveYes
I get the same error even when I only use DoCmd.Close

1589365960310.png
1589365992645.png
 

June7

AWF VIP
Local time
Today, 07:03
Joined
Mar 9, 2014
Messages
5,463
Well, error message seems clear enough. Current event is processing. Can't close form while that event is processing.

Didn't answer my question nor respond to my suggestion.
 

Gismo

Registered User.
Local time
Today, 18:03
Joined
Jun 12, 2017
Messages
1,298
Well, error message seems clear enough. Current event is processing. Can't close form while that event is processing.

Didn't answer my question nor respond to my suggestion.
Yes, thank you, did not quite understand the error, the form was opening while i was closing it
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:03
Joined
Feb 28, 2001
Messages
27,133
You gave us a peek at the code in post #5 and you did not have Option Explicit. Therefore, if you really DID have asSaveYes (as a typo), what you did was create a variable (of type Variant) named asSaveYes, probably with a value of 0. I looked it up. In that context, a value of 0 would be interpreted as acSavePrompt which probably means Access wanted to pop up a yes/no prompt for saving whatever it was saving.

It is probably not a good idea to omit "Option Explicit" in a code segment. It will take longer for the initial compilation if you are a sloppy typist like I am. But it will catch all spelling errors for you, which is a good thing.
 
Last edited:

Users who are viewing this thread

Top Bottom