I have a database with a login form, and upon a successful login the main navigation form is supposed to open and the login form is supposed to close... except that the login form refuses to close itself and instead throws "Run-time error '2585': This action can't be carried out while processing a form or report event."
Here's what I've got for the code:
Private Sub buttonLogin_Click()
Dim hash As New CMD5
Dim salt As String
Dim result As String
Dim rs As DAO.Recordset
Dim rc As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblCurrentUser", dbOpenDynaset)
Set rc = CurrentDb.OpenRecordset("tblCustom", dbOpenDynaset)
'----Check If User ID Or Password Is Null----
If IsNull(ID) Then
MsgBox "Please enter your User ID", vbOKOnly
Me.ID.SetFocus
Exit Sub
End If
If IsNull(Password) Then
MsgBox "Please enter your password", vbOKOnly
Me.Password.SetFocus
Exit Sub
End If
'----Validate Login Information----
' This section builds the salted MD5 hash and compares
' it to the password stored in the personnel table.
result = DLookup("Password", "tblPersonnel", "EmpID = '" & ID & "'")
salt = ID & "-" & Password
If result <> hash.MD5(salt) Then
MsgBox "Please enter a valid User ID and Password", vbOKOnly
Me.ID.SetFocus
Exit Sub
End If
'----Check User Access Permission----
If DLookup("AccessLevel", "tblPersonnel", "EmpID = '" & ID & "'") = 0 Then
MsgBox "Access denied, please contact " & rc![DBA] & " for database access.", vbExclamation
Me.ID.SetFocus
Exit Sub
End If
'----Store Current User and Access Level to temp table----
rs.Edit
rs![UserID] = ID
rs![AccessLevel] = DLookup("AccessLevel", "tblPersonnel", "EmpID = '" & ID & "'")
rs.Update
rs.Close
rc.Close
'----Open Navigation Form, close Login----
DoCmd.OpenForm "frmNavMain", acNormal
DoCmd.Close acForm, "frmLogin"
End Sub
So as you can see I've got a lot going on when the user logs in. Any invalid entries are caught and the sub is exited if that happens, but assuming everything checks out, the sub just rolls down to the end there and opens the nav form and then it should close itself. The debugger points specifically at the DoCmd.Close acForm, "frmLogin" line at the bottom every time. I've tried moving that line into frmNavMain Form_OnLoad() but it still throws the same run-time error.
What am I missing here?
Aucun commentaire:
Enregistrer un commentaire