Dear Access Guru's,
I have a "Change Password" form that is quite simple.
Users can select their username from a combo box, enter their old password, enter their new password and confirm that password.
Now - with the code that I have, it changes everyone's password in that table.....
herewith the code behind the combo box:
Code:
SELECT [Employees].[ID], Employees.[FullName] FROM Employees ORDER BY [FullName];
and herewith the code behind the form:
Code:
Private Sub changepass_Click()
'Check to see if a Username has been selected
If Len(Me.uname & "") = 0 Then ' This has been studied and oddly enough is the most efficient test of an empty textbox.
MsgBox "You must select a username to proceed.", vbExclamation + vbOKOnly, "Required Data - Select Username."
uname.SetFocus
Exit Sub
End If
'Check to see if data is entered into the old password box
If Len(Me.passw & "") = 0 Then ' This has been studied and oddly enough is the most efficient test of an empty textbox.
MsgBox "You must enter your old password.", vbCritical + vbOKOnly, "Required Data - Old Password."
passw.SetFocus
Exit Sub
End If
'Check to see if data is entered into the new password box
If Len(Me.newpass & "") = 0 Then
MsgBox "You must enter a new Password.", vbCritical + vbOKOnly, "Required Data - New Password."
newpass.SetFocus
Exit Sub
End If
'Check to see if data is entered into the confirm new password box
If Len(Me.newpassconf & "") = 0 Then
MsgBox "You must confirm your new Password.", vbCritical + vbOKOnly, "Required Data - Confirm Password."
newpassconf.SetFocus
Exit Sub
End If
'lets compare the new passwords...
If Me.newpass <> Me.newpassconf Then
MsgBox "Please reenter the confirmation password, it doesn't match the suggested new password", vbCritical + vbOKOnly, "Required Data - Passwords do not match."
Me.newpassconf.SetFocus
Exit Sub
End If
'Check value of the old password in tblEmployees to see if this matches value chosen in the old password box
If Me.passw = DLookup("Password", "Employees", _
"[ID]='" & Me.uname & "'") Then ' Since it's a Text field it must be delimited by ' or "
'ID = Me.uname *****WITH THIS IS ENABLED I GET A "CANT UPDATE FIELD" error
'Lets update the "Employees" table password field...
Dim db As DAO.Database
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "UPDATE [Employees] SET [Password] = '" & Replace(Me.newpass, "'", "''") & "';"
db.Execute strSQL, dbFailOnError
MsgBox "Your Password has been changed.", vbInformation + vbOKOnly, "Password Changed!"
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Control Panel"
Else
MsgBox "Your Old Password is invalid. Please try again or press CANCEL.", vbCritical + vbOKOnly, "Invalid Entry!"
passw.SetFocus
End If
Proc_Exit:
Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in ChangePass:" & vbCrLf & Err.Description
Resume Proc_Exit
End Sub
I think the problem is in the update table section - I need to
tell access only to update the selected usernames password...
Any help would be highly appreciated.