Error 2585 when closing form

Summit

Registered User.
Local time
Yesterday, 22:58
Joined
Apr 26, 2012
Messages
22
Hi all,

I get this error 2585 This action can't be carried out while processing a form or report event. This happens when I enter a password into my form in order to open any other one. When the password is correct, I want it to open an administrator form, close the form (Main Start) which has the button to open the login form, and close the login form . However when the password is correct this error pops up and the login form does not close. Any help would be appreciated.

Private Sub txtPassword_LostFocus()
Dim PassWord As String
strPassword = "12345"
If Me.txtPassword = strPassword Then
DoCmd.OpenForm "Menuboard Admin"
DoCmd.Close acForm, "Menuboard Main Start"
DoCmd.Close acForm, "Menuboard Login"
Else
MsgBox ("You're not authorized for Administrator access.")
End If
End Sub
 
Try the after update event instead of the lost focus event.
 
Try the after update event instead of the lost focus event.

Thank you very much that worked! How come after update worked and lost focus did not?

And one more question. What would the code be for if the password is incorrect, clear the text that was entered into the textbox. And I'm assuming this code would be placed after "else" in the code above.
 
Last edited:
As the error implies, in the lost focus event Access is still working on leaving the textbox, so it can't close the form (like you can't close a door if you're foot is still in it). In the after update event, it's done with the textbox thus free to close the form.

You can set the textbox value to Null or "" to clear it.
 
As the error implies, in the lost focus event Access is still working on leaving the textbox, so it can't close the form (like you can't close a door if you're foot is still in it). In the after update event, it's done with the textbox thus free to close the form.

You can set the textbox value to Null or "" to clear it.

Perfect, worked like a charm. Thanks!!
 
Try the after update event instead of the lost focus event.

Hello dear pbaldy
I have a database which has a Login form and a Main Menu. I want when users enter their Username and Password and then click Enter button, Login form be closed and then Main Menu be opened.
I put the code on Enter button, but in gives error 2585.

Can you please help me to solve this problem?

Thanks in advance
 
Agree, and what exactly is your code and where exactly is it (what event, what control)?
 
Agree, and what exactly is your code and where exactly is it (what event, what control)?

Thanks;

The Login form controls are:
cboUser
txtPassword
cmdLogin
cmdCancel



The code is put on Enter and Click events of cmdLogin. The using code is a function called LoginCode:

Public Sub LoginCode()
If IsNull([cboUser]) = True Then 'Check UserName
MsgBox "Please choose the username."
ElseIf IsNull([txtPassword]) = True Then 'Check Password
MsgBox "Please enter your password."
Else
'Compare value of txtPassword with the saved Password in tblUsers
If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[Username]='" & Me.cboUser.Value & "'") Then
strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
strRole = DLookup("Role", "tblUsers", "[Username]='" & Me.cboUser.Value & "'") 'set the value of strRole declared as Global Variable
If DLookup("[Gender]", "tblUsers", "[Username]='" & Me.cboUser.Value & "'") Like "Male" Then
MsgBox "Welcome Mr. " & strUser & "!", vbOKOnly, "Welcome"
Else
MsgBox "Welcome Ms. " & strUser & "!", vbOKOnly, "Welcome"
End If
DoCmd.OpenForm "frmMainMenu"
Else
MsgBox "You are not allowed to use this database. Contact with the administrator", vbCritical, "Warning!"
Application.Quit
End If
End If
End Sub
 
For starters try taking it out of the enter event. Leave it in the click event only.
 
Why quit after showing the warning? What if the user had a mistake?
Take him back to the login screen having also the quit button.

Code should only be in the OnClick event.
Put code directly into the event. No need for another SUB.

Where do you close the login form?

Please put you code into a
Code:
 section
 
Last edited:

Users who are viewing this thread

Back
Top Bottom