Error 2585 trying to close form

K

Ken Warthen

In an Access 2007 database, I have a login form that processes a user name
and password and then opens a Switchboard form. I created a routine to close
the login form that is called from the On Activate event of the Switchboard
form. Whenever I run the program an error 2585 is generated with the
statement "This action can't be carried out while processing a form or
report." Here's the offending line of code: DoCmd.Close ObjectType:=acForm,
ObjectName:=strFormName
The strFormName value is "frmLogin". Can anyone tell me what I'm doing
wrong, or if there is a better way to close the login form once the
Switcboard form is displayed?

TIA,

Ken Warthen
(e-mail address removed)
 
L

Linq Adams via AccessMonster.com

This situation would normally be handled by, in the login form, opening the
switchboard then closing your loginform, rather than by closing it in the
newly opened switchboard.

Open Switchboard
Close Login

If this doesn't work, post the code (or Macro commands) in it's entirety,
that you are/were using. The error message you posted actually says that the

"OnOpen/OnClose property setting contains an invalid action for the property.
When you click OK an Action Failed dialog box will display the name of the
macro that failed and its arguments.@1@611909@1

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
K

Ken Warthen

Thanks for the help Linq. Here's the routine's code. The offending line
follows the asterisked remark line . — Ken

Private Sub cmdLogin_Click()

'Check for user name entry.
If IsNull(Me.txtUserName) = True Or Me.txtUserName.Value = "" Then
MsgBox "You must enter or select a user name.", vbOKOnly, "Missing
User Name"
Me.txtUserName.SetFocus
Exit Sub
End If
'Check for password entry.
If IsNull(Me.txtPassword) = True Or Me.txtPassword.Value = "" Then
MsgBox "You must enter a password.", vbOKOnly, "Missing Password"
Me.txtPassword.SetFocus
Exit Sub
End If

'Validate password
Dim db As Database
Dim rst As Recordset
Dim strPassword As String
Dim strUserName As String
Dim blnValidPassword As Boolean
Dim intLoginAttempts As Integer

strUserName = Me.txtUserName.Value
strPassword = Me.txtPassword.Value

Set db = CurrentDb
Set rst = db.OpenRecordset("tblDSiEmployees")
With rst
blnValidPassword = False
.MoveFirst
Do Until .EOF
If .Fields("Employee Name").Value = strUserName Then
intLoginAttempts = .Fields("LoginAttempts").Value
If .Fields("Password").Value = strPassword Then
blnValidPassword = True
Exit Do
End If
End If
.MoveNext
Loop
End With
rst.Close
Set db = Nothing

'If login attempts are greater than 3 display message, reset login
attempts and quit application.
If intLoginAttempts >= 2 Then
MsgBox "Too many login attempts." & vbCrLf & "You must not be who
you think you are.", vbOKOnly, "Failed Login"
DoCmd.Close acForm, "frmLogin"
Call ResetLoginAttempts
Call subQuitApplication
Exit Sub
End If

If blnValidPassword = True Then
'Check for Administrator
If CheckForAdministratorRights(strUserName) = True Then
gstrUserRights = "Administrator"
Else:
gstrUserRights = "End user"
End If
'Set Global User name value.
gstrUserName = strUserName
'Reset login attempts to zero.
Call ResetLoginAttempts
'Close login form and enter database
DoCmd.OpenForm "Switchboard", acNormal

'*** The following is the line of code that generates error 2585 ***
DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name
Else:
'Increment login attempts and try again.
Set db = CurrentDb
Set rst = db.OpenRecordset("tblDSiEmployees")
With rst
.Edit
.MoveFirst
Do Until .EOF
If .Fields("Employee Name").Value = strUserName Then
intLoginAttempts = .Fields("LoginAttempts").Value
Debug.Print intLoginAttempts
intLoginAttempts = intLoginAttempts + 1
.Edit
.Fields("LoginAttempts") = intLoginAttempts
.Update
Exit Do
End If
.MoveNext
Loop
End With
rst.Close
Set db = Nothing
'Display invalid password message
MsgBox "Invalid password. Please re-enter your password.",
vbOKOnly, "Invalid Password"
Me.txtPassword.SetFocus
End If
End Sub
 

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