none
Password Change in ms application FE RRS feed

  • Question

  • I have a problem to create a code to be used for my user to change their own password in my ms Access 2016 developed application see below: 

    The problem is on this code in bold below it is not updating the password on the staff table. 

    src = " UPDATE tblStaff SET EmpPassword = 'Me.txtStaffPasswords' "
    src = src & "WHERE (((EmpName)='Me.CboEmpName'))"
    CurrentDb.Execute src

    Option Compare Database
    Option Explicit

    Private Sub CmdChgPW_Click()
    Dim src As String
    If IsNull(Me.txtNewPW1) Or IsNull(Me.txtNewPW2) Then
    MsgBox "Please enter new password", vbInformation, "New password Required"
    Me.txtNewPW1 = ""
    Me.txtNewPW2 = ""
    Exit Sub
    Else
    If Me.txtNewPW1 <> Me.txtNewPW2 Then
    MsgBox "Passwords do not match", vbInformation, "MissMatch"
    Me.txtNewPW1 = ""
    Me.txtNewPW2 = ""
    Me.txtNewPW2.SetFocus
    Exit Sub
    End If
    End If
    src = " UPDATE tblStaff SET EmpPassword = 'Me.txtStaffPasswords' "
    src = src & "WHERE (((EmpName)='Me.CboEmpName'))"
    CurrentDb.Execute src
    MsgBox "Change password successful", vbInformation, "Change Password"
    DoCmd.Close
    End Sub

    Private Sub CmdChgPWProceed_Click()
    Dim sMyStaffId As String
    If IsNull(Me.CboEmpName) Then
    MsgBox "Please enter login", vbInformation, "Log in required"
    Me.CboEmpName.SetFocus
    txtNewPW1.Visible = False
    txtNewPW2.Visible = False
    ElseIf IsNull(Me.txtStaffPasswords) Then
    MsgBox "Please enter password", vbInformation, "Password required"
    Me.txtStaffPasswords.SetFocus
    txtNewPW1.Visible = False
    txtNewPW2.Visible = False
    Else
    If Me.txtStaffPasswords.Value = DLookup("EmpPassword", "tblStaff", "[StaffID]=" & Me.CboEmpName.Value) Then
    sMyStaffId = Me.CboEmpName.Value
    MsgBox "Login and Password correct, proceed to change password", vbInformation, "Login successful"
    CboEmpName.Visible = False
    txtStaffPasswords.Visible = False
    txtNewPW1.Visible = True
    txtNewPW2.Visible = True
    Else
    MsgBox "Incorrect Login or Password, contact Admin", vbInformation, "Login failure"
    txtNewPW1.Visible = False
    txtNewPW2.Visible = False
    End If
    End If
    End Sub

    The staff table has the following fields:

    StaffId (PK)

    EmpName (Short Text)

    EmpPassword (Short Text)

    The form has the following fields:

    - CboEmpName

    - txtStaffPasswords

    - txtNewPW1

    - txNewPW2

    Regards

    Chris


    • Edited by ChrisCKP Monday, April 24, 2017 9:57 AM
    Monday, April 24, 2017 9:56 AM

All replies

  • Since none of the lines are in Bold lettering, no one can tell which line you are asking about. Also, when you step through the code, is there an error message? If so, what does it say?
    Tuesday, April 25, 2017 6:55 PM
  • Tickling the back of my mind...

    Cbo is a combo box. The content of a cbo is 0, 1, 2, etc. You will need to know what the number represents.


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Tuesday, April 25, 2017 6:59 PM
  • src = " UPDATE tblStaff SET EmpPassword = 'Me.txtStaffPasswords' "
    src = src & "WHERE (((EmpName)='Me.CboEmpName'))"
    CurrentDb.Execute src

    Hi Chris,

    You could try:

        src = "UPDATE tblStaff SET EmpPassword = '" & Me.txtStaffPasswords & "'" _
              & " WHERE EmpName = '" & Me.CboEmpName & "'"
        CurrentDb.Execute src

    Imb.

    Tuesday, April 25, 2017 8:53 PM
  • Try

    src = "UPDATE tblStaff SET EmpPassword = '" & Me.txtStaffPasswords & "' "
    src = src & "WHERE (EmpName='" & Me.CboEmpName & "')"


    Daniel Pineault, 2010-2016 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Tuesday, April 25, 2017 11:59 PM