Results 1 to 5 of 5
  1. #1
    hbird10 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    2

    Need help with vba code for user password change form.

    Hello all. I am working on the code for a user password change form and an having some difficulty with the code. What I have is below.



    Table = tblUsers
    Field 1 = UserID (autonumber)
    Field 2 = UserName (text)
    Field 3 = Password (text)

    Form = frmUsers
    Textbox 1 = txtUser (this is linked to UserName)
    Textbox 2 = txtPassword (this is linked to Password)
    Textbox 3 = txtPassword2 (this is where a new password will be entered)
    Textbox 4 = txtConfirmPW (this is where the new password will be entered again for confirmation)
    Testbox 5 = UserID (this one is hidden)

    Below is the code I have so far. It looks like it's getting hung on the strSQL = "UPDATE tblUsers SET Password=" & "" & Me.txtPassword2 & "'WHERE UserID=" & Me.txtUserID

    Any and all help would be appreciated!

    Private Sub Command7_Click()

    Dim strOldPassword As String
    Dim strSQL As String
    Dim intUserID As Integer

    intUserID = Me.UserID

    If IsNull(Me.txtUser) Or Me.txtUser = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.txtUser.SetFocus
    Exit Sub
    End If

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
    MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
    Me.txtPassword.SetFocus
    Exit Sub
    End If

    strOldPassword = DLookup("[Password]", "tblUsers", "[UserID]=" & intUserID)
    Select Case strOldPassword
    Case Is = Me.txtPassword

    strSQL = "UPDATE tblUsers SET Password=" & "" & Me.txtPassword2 & "'WHERE UserID=" & Me.txtUserID
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True

    MsgBox "Password has been changed", vbInformation, "Password Changed"
    Case Is <> Me.txtPassword
    MsgBox "The Old Password does not match", vbInformation, "Type Correct Password"

    End Select
    Exit_Command7_Click:
    Exit Sub

    Err_Command7_Click:
    MsgBox Err.Description
    Resume Exit_Command7_Click

    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Post code between CODE tags to retain indentation and will be more readable and it will be easier to find your post narrative.

    Missing an apostrophe and need a space after apostrophe before WHERE:

    strSQL = "UPDATE tblUsers SET Password= '" & Me.txtPassword2 & "' WHERE UserID=" & Me.txtUserID
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Code:
    Private Sub Command7_Click()
    Dim strOldPassword As String
    Dim strSQL As String
    Dim intUserID As Integer
    Dim vMsg, vStat
    
    txtUser = Environ("Username")
    'If IsNull(Me.txtUser) Or Me.txtUser = "" Then
    '    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    '    Me.txtUser.SetFocus
    '    Exit Sub
    'End If
    
    vMsg = ""
    vStat = "Error"
    
    Select Case True
        Case IsNull(txtPassword)
            vMsg = "You must enter a Password."
            txtPassword.SetFocus
        
        Case txtPassword = ""
            vMsg = "You must enter a Password."
            txtPassword.SetFocus
        
        Case IsNull(txtPassword2)
            vMsg = "You must enter a Password."
            txtPassword2.SetFocus
        
        Case txtPassword2 = ""
            vMsg = "You must enter a NEW Password."
            txtPassword2.SetFocus
        
        Case IsNull(txtConfirmPW)
            vMsg = "You must enter a Confirmation New Password."
            txtPassword2.SetFocus
        
        Case txtConfirmPW = ""
            vMsg = "You must enter a Confirmation New Password."
            txtConfirmPW.SetFocus
        
        Case txtConfirmPW <> txtConfirm2
            vMsg = "New password and Confirmation Password do not match."
            txtConfirmPW.SetFocus
    End Select
    
    If vMsg = "" Then
        strOldPassword = DLookup("[Password]", "tblUsers", "[UserID]=" & intUserID)
        If txtPassword <> strOldPassword Then
            vMsg = "The Old Password does not match"
        Else
            strSQL = "UPDATE tblUsers SET Password=" & "" & Me.txtPassword2 & "'WHERE UserID=" & Me.txtUserID
            DoCmd.SetWarnings False
            DoCmd.RunSQL strSQL
            DoCmd.SetWarnings True
            vMsg = "Password has been changed"
            vStat = "Success"
    End If
    MsgBox vMsg, vbCritical, vStat
    End Sub

  4. #4
    hbird10 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    2
    Thank you June 7. I'm getting a "Compile error: Method or data member not found" and ".txtPassword2" highlights on the strSQL line in the editor. The textbox where the new password is entered is named txtPassword2.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    The code is behind the form that has txtPassword2 textbox? If that really is name of textbox, see no reason for code not to work.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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. Replies: 1
    Last Post: 06-22-2012, 08:05 AM
  3. Help fixing a code to change password programatically
    By smartflashes in forum Programming
    Replies: 3
    Last Post: 01-19-2012, 10:20 PM
  4. Change password form
    By funkygoorilla in forum Forms
    Replies: 8
    Last Post: 01-17-2012, 08:37 PM
  5. Change Password Form using VBA
    By anwaar in forum Programming
    Replies: 2
    Last Post: 09-02-2011, 01:29 PM

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