Good day,
I have a login form [frmLogin] with combobox [cboUser] to select a User. Password is textbox [txtPassword]. The table containing the data is called [tblUsers]. [tblUsers] contains the following elements:
UserID (AutoNmber)
Fullname (Text)
Password (Text)
PWReset (Yes/No) set to True/False format
AccessLevelID (Number)
I also have a change password form [frmChangePassword].
On the login form, there is a change password button that takes the user to the change password form, which is filtered for the current user, and allows them to change the password, which then updates the tblUsers with the password for the correct User. This button and change password function work fine.
I have code in the AfterUpdate event of [txtPassword] on the login form that checks to see if the PWReset is set to True. If it is True, the change password form should open, filter for the current user, and allow them to change the password, just as they would when clicking the change password button on the login form. This, however, does not happen.
This is the code for the AfterUpdate event on [txtPassword] on [frmLogin]:
Code:
Private Sub txtPassword_AfterUpdate()
'Check that User is selected
If IsNull(Me.cboUser) Then
MsgBox "Please select a user", vbCritical
Me.cboUser.SetFocus
Else
'Check for correct password
If Me.txtPassword = Me.cboUser.Column(2) Then
'Check if password needs to be reset
If Me.cboUser.Column(3) = True Then
DoCmd.OpenForm "frmChangePassword", , , [UserID] = " & Me.cboUser"
End If
DoCmd.OpenForm "frmNMD_Switchboard"
Me.Visible = False
Else
MsgBox "Password does not match, please re-enter your password", vboOkOnly + vbExclamation
Me.txtPassword = Null
Me.txtPassword.SetFocus
End If
End If
End Sub
When the PWReset is True on tblUsers, I receive the following error when logging in: "Run-time error '2465': NMD v.10 can't find the field '|1' referred to in your expression." Debug highlights this part:
Code:
DoCmd.OpenForm "frmChangePassword", , , [UserID] = " & Me.cboUser"
The change password button has this:
Code:
Private Sub btn_ChangePassword_Click()
DoCmd.OpenForm "frmChangePassword", , , [UserID] = " & Me.cboUser"
End Sub
...and it works perfectly. What is wrong with the code in my AfterUpdate event?
Your time and assistance are much appreciated.