I read these so often to get help and now I am going to post my first thread. Here is my code:
Private Sub cmdChangePwd_Click()
If Len(Me.txtOldPwd & "") = 0 Then
MsgBox "You must enter your old password.", vbCritical + vbOKOnly, "Required Data - Old Password."
txtOldPwd.SetFocus
Exit Sub
End If
'Check to see if data is entered into the new password box
If Len(Me.txtNewPwd & "") = 0 Then
MsgBox "You must enter a new Password.", vbCritical + vbOKOnly, "Required Data - New Password."
txtNewPwd.SetFocus
Exit Sub
End If
'Check to see if data is entered into the confirm new password box
If Len(Me.txtNewPwdChk & "") = 0 Then
MsgBox "You must confirm your new Password.", vbCritical + vbOKOnly, "Required Data - Confirm Password."
txtNewPwdChk.SetFocus
Exit Sub
End If
'Compare the new passwords...
If Me.txtNewPwd <> Me.txtNewPwdChk Then
MsgBox "Please reenter the confirmation password, it doesn't match new password", vbCritical + vbOKOnly, "Required Data - Passwords do not match."
Me.txtNewPwdChk.SetFocus
Exit Sub
End If
'Check value of the old password in tblUsers to see if this matches value chosen in the old password box
If Me.txtOldPwd = DLookup("[Password]", "tblUsers", "[UserName]='" & Me.cboUser & "'") Then
'If Me.txtOldPwd = Me.Password And Me.UserName = Me.cboUser Then
'Update the "tblUsers" table password field...
Dim db As DAO.Database
Dim StrSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
StrSQL = "UPDATE [tblUsers] SET [Password] = '" & Replace(Me.txtNewPwd, "'", "''") & "'Where '[UserName] = " & Me.cboUser & "'"
db.Execute StrSQL, dbFailOnError
MsgBox "Your Password has been changed.", vbInformation + vbOKOnly, "Password Changed!"
DoCmd.Close acForm, Me.Name
Else
MsgBox "Your Old Password is invalid. Please try again or press CANCEL.", vbCritical + vbOKOnly, "Invalid Entry!"
Me.txtOldPwd.SetFocus
End If
Proc_Exit:
Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdChangePwd:" & vbCrLf & Err.Description
Resume Proc_Exit
End
End Sub
The bolded code is the one I can't seem to do anything with, it will always update all users with the same password. You will see that I have played around with many different codes and some I have left, I am just not using them. I have tried so many things so, now I need to ask the experts. Any assistance would be great.