Results 1 to 5 of 5
  1. #1
    bongazi is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Posts
    3

    Change Password field in Table not working

    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.[FullNameFROM 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 strSQLdbFailOnError
        MsgBox 
    "Your Password has been changed."vbInformation vbOKOnly"Password Changed!"
          
    DoCmd.Close acFormMe.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.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You are correct, you need a WHERE clause in your SQL statement.

  3. #3
    bongazi is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Posts
    3
    Quote Originally Posted by RuralGuy View Post
    You are correct, you need a WHERE clause in your SQL statement.
    Hi RuralGuy,

    me being an utter newbie to access - I have tried the WHERE clause without success. This is what I did... but I get a syntax error. That is why
    I am turning here for help.

    Code:
    strSQL "UPDATE [Employees] SET [Password] = '" Replace(Me.newpass"'""''") & "';" Where ID=" & Me.uname.Value 
    Thank you for your time...

    Regards,
    Bongazi

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Hi
    I think this may work.

    strSQL = "UPDATE [Employees] SET [Password] = '" & Replace Me.newpass & "'Where ID=" & Me.uname.Value

    Regards
    Bob


  5. #5
    bongazi is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Posts
    3
    Thank you Bob,

    John Vinson of UA helped me change the code - but it works now:

    strSQL = "UPDATE [Employees] SET [Password] = '" & Replace(Me.newpass, "'", "''") & _
    "' WHERE [ID] = " & Me.cboUname & ";"


    Regards,
    Bongazi

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 field to "password" type
    By ducecoop in forum Access
    Replies: 3
    Last Post: 11-11-2010, 12:02 PM
  3. Login/Password Code not working
    By eww in forum Programming
    Replies: 3
    Last Post: 09-21-2010, 10:49 AM
  4. Password change issues
    By westeral in forum Access
    Replies: 0
    Last Post: 11-28-2009, 09:20 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