Hello,
I have a weird one for you and I can't for the life of me work out what is going on.
I have code in the form which checks whether a user's password needs to be updated and if so prompts the user to do this. Everything works fine until the last line of code which should just close the form (there is no code in the on close event of the form), instead it updates the data in the first record in the table to the new password entered for a different record. Below is the code, it's the docmd.close event that is causing the problem.
Code:
Private Sub cmdLogin_Click()
Dim DashboardPic As String
Dim rs As DAO.Recordset
'Check that both a username and password have been added
If IsNull(Me.txtPassword) Or IsNull(Me.cboUserName) Then
MsgBox "You must enter both a username and password", vbOKOnly, "Missing Data"
Exit Sub
End If
'Check the User's Password matches that in the users table
If Me.txtPassword.Value <> DLookup("Password", "tblUsers", _
"[ID]=" & Me.cboUserName.Value) Then
' Inform the user of an incorrect password and close
MsgBox "Password Invalid. Please try again", vbOKOnly, "Invalid Entry"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check if the change password check is true. If so, make the user change their password
If DLookup("changePassword", "tblUsers", "[ID]=" & Me.cboUserName.Value) = True Then
Password = InputBox("Your password must be changed", "Set password")
'Update the password
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblUsers WHERE [ID]=" & Me.cboUserName.Value)
rs.Edit
rs("Password") = Password
rs("changePassword") = False
rs.Update
rs.Close
Set rs = Nothing
End If
' Open frmDashboard The On Open even of frmDashboard takes the userID from
' This form and saves it for furture reference on frmDashboard
DoCmd.OpenForm "frmDashboard"
' Close this form
DoCmd.Close acForm, "frmLogin", acSaveYes
End Sub