I am having an issue with my login security that I built through VBA. Everything works pretty well, but I am having issues when I force the user to reset their password.
I'm using this tutorial in order to build my security:
http://www.accesssecurityblog.com/post/2011/04/02/Login-Security-using-Access-VBA.aspx
The sample provided with that tutorial works flawlessly, but when I run my code (copied and pasted from their functioning model) I get a window that pops up requesting the UserID of the user wanting to change their password.
Here is the code that I am using for the login form.
Code:
Private Sub txtPassword_AfterUpdate()
'Check that a user is selected
If IsNull(Me.cboUser) Then
'If no user is selected, display message box
MsgBox "Please select a user before entering a password.", vbCritical
'Move cursor into USER field
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
MsgBox "Your UserID is " & Me.cboUser & ". Please enter your UserID into the next window to reset your password.", vbOKOnly
DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
End If
DoCmd.OpenForm "frmMainMenu"
Me.Visible = False
Else
'Upon incorrect password, display message box
MsgBox "Incorrect password. Please try again.", vbCritical
'Empty PASSWORD field for re-entry
Me.txtPassword = Null
'Move cursor to the PASSWORD field
Me.txtPassword.SetFocus
End If
End If
End Sub
When I debug the error, it shows that this line is the problem:
Code:
DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
I thought something may have been wrong, so I used some code to show what UserID is used at the moment. I thought that maybe the UserID wasn't getting picked up, but that isn't the case. This line of code shows the appropriate UserID.
Code:
MsgBox "Your UserID is " & Me.cboUser & ". Please enter your UserID into the next window to reset your password.", vbOKOnly
When the correct UserID is put in entered, you can successfully change the password, but if the wrong ID is entered the password gets assigned to a new user.
I'm not sure where I'm going wrong. As I said, the example provided by the tutorial works perfectly, but I cannot get this DB to function the same way.
Thanks for any help guys!