Results 1 to 2 of 2
  1. #1
    avaleigh is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    1

    Change Password Form - updating all users with the password

    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.

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I'm not sure why you are using the Replace() function but you need a space between the single quote and the W in Where, and the single quote before [Username] should be after [Username]= . Shown in red below. Based on what you show, the bound column of cboUser is a text value. Is that correct?


    StrSQL = "UPDATE [tblUsers] SET [Password] = '" & Replace(Me.txtNewPwd, "'", "''") & "' Where [UserName] = '" & Me.cboUser & "'"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Change Password form
    By turbo910 in forum Forms
    Replies: 16
    Last Post: 05-07-2015, 09:02 AM
  2. Change password form
    By funkygoorilla in forum Forms
    Replies: 8
    Last Post: 01-17-2012, 08:37 PM
  3. Change Password Form using VBA
    By anwaar in forum Programming
    Replies: 2
    Last Post: 09-02-2011, 01:29 PM
  4. Change username and password form..
    By Mrcams in forum Access
    Replies: 9
    Last Post: 12-07-2010, 11:22 AM
  5. Change from old password to new password
    By richy in forum Security
    Replies: 0
    Last Post: 11-17-2005, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums