Change password code not working (1 Viewer)

wrightyrx7

Registered User.
Local time
Today, 03:11
Joined
Sep 4, 2014
Messages
104
Hi all,

I have found some code online and trying to adapt it to suit my needs.

The part its failing at is marked in red.

I get error message:
Run-time error '2465':
Microsoft Access can't find the field '|1' referred to in your expression.




Code:
Option Compare Database
Option Explicit
Private Sub Command1_Click()
Dim pUser As Long


'Check to see if data is entered into the UserName combo box

    If IsNull(Me.txtCurrent) Or Me.txtCurrent = "" Then
      MsgBox "You must enter a your current password.", vbOKOnly, "Required Data"
        Me.txtCurrent.SetFocus
        Exit Sub
    End If

    'Check to see if data is entered into the password box

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

    'Check value of password in tblUsers to see if this
    'matches value chosen in combo box
        pUser = DLookup("[ID]", "Users Extended", "Username='" & cUser & "'")
    If Me.txtCurrent.Value = DLookup("Password", "Users", "ID=" & pUser) Then

          
        'Check new and confim passwords are the same
        If Me.txtNew.Value = Me.txtConfirm.Value Then
         

        'Changes password on tblUsers and Close form
        [COLOR="Red"][Password] = Me.txtNew.Value[/COLOR]
        
        DoCmd.Close acForm, "Change Password", acSaveNo
        DoCmd.OpenForm "Call Log"
        MsgBox "Password Changed"

        Else
      MsgBox "Passwords Do not match. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtConfirm.SetFocus
    End If
    Else
    MsgBox "Incorrect Password"
    Exit Sub
    End If
End Sub
 
Last edited:

Minty

AWF VIP
Local time
Today, 10:11
Joined
Jul 26, 2013
Messages
10,355
You can't update [Password] in the table using that code. VBA doesn't know what user you are trying to update or even where [Password] exists.

You would need to either open that record as a record set or as it's a simple single field update run a simple SQL update statement.

Alternatively if the password is loaded into a bound hidden field on the form you could update it using
Code:
 Me.hiddenpassowordfield =  Me.txtNew.Value
 

wrightyrx7

Registered User.
Local time
Today, 03:11
Joined
Sep 4, 2014
Messages
104
Hi Minty,

I solved it with this code

Code:
        'Changes password on tblUsers and Close form
        CurrentDb.Execute "Update Users set Password = '" & txtNew & "' where [ID] =" & pUser

Thanks for your suggestions.
 

Users who are viewing this thread

Top Bottom