Solved

Changing User Password

Posted on 2013-11-22
6
426 Views
Last Modified: 2013-11-25
I have a form that allows the user to change his password by entering username, old password and new password. All three fields are of text datatype cboEmployee is a combobox with user list
With a simple update query to run, but it's not updating the table.

Here is the code in my submit button
       
Dim strSQL As String
strSQL = "UPDATE tblEmployees SET strEmpPassword = ' " & Me.txtNewPassword & " ' WHERE(strEmpName) = ' " & Me.cboEmployee.Value & " ' and (strEmpPassword) = ' " & Me.txtNewPassword & " ';"        
DoCmd.RunSQL (strSQL)
       
Please assist
0
Comment
Question by:ernie_shah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 500 total points
ID: 39669857
try this, copy and paste

Dim strSQL As String
strSQL = "UPDATE tblEmployees SET strEmpPassword ='" & Me.txtNewPassword & "' WHERE (strEmpName) ='" & Me.cboEmployee.Value & "' and (strEmpPassword) ='" & Me.txtNewPassword & "';"        
DoCmd.RunSQL strSQL


or this

Dim strSQL As String
strSQL = "UPDATE tblEmployees SET strEmpPassword ='" & Me.txtNewPassword & "' WHERE (strEmpName) =" & chr(34) & Me.cboEmployee.Value & chr(34) & " and (strEmpPassword) ='" & Me.txtNewPassword & "';"        
DoCmd.RunSQL strSQL
0
 

Author Comment

by:ernie_shah
ID: 39669926
Thanks, but I keep getting the message you are about to update 0 records
see my entire code below:

Private Sub Command4_Click()


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



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


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

    If Me.txtOldPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee
       
   
    Dim strSQL As String
    strSQL = "UPDATE tblEmployees SET strEmpPassword ='" & Me.txtNewPassword & "' WHERE (strEmpName) =" & Chr(34) & Me.cboEmployee.Value & Chr(34) & " and (strEmpPassword) ='" & Me.txtOldPassword & "';"
    DoCmd.RunSQL strSQL
    DoCmd.OpenForm "frmLogon", acNormal
    DoCmd.Close acForm, "frmChangePassword", acSaveYes

     Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtOldPassword.SetFocus
    End If
   

   
End Sub
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39669983
Dim strSQL As String
    strSQL = "UPDATE tblEmployees SET strEmpPassword ='" & Me.txtNewPassword & "' WHERE (strEmpName) =" & Chr(34) & Me.cboEmployee.Value & Chr(34) & " and (strEmpPassword) ='" & Me.txtOldPassword & "';"

'ADD this line

Debug.print strSQL


    DoCmd.RunSQL strSQL


run the codes again and copy what was printed in the immediate window and paste here

.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:ernie_shah
ID: 39670036
I am not getting anything displayed but the attached when I click on my save/update command button.

My table structure is as follows:
lngEmpID AutoNumber
strEmpName text
strEmpPassword text
strAccess text

The combo box is derived from a query that contains the id, and name. It displays the name but is bound to the id, can this have anything to do with the error?
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39670068
<The combo box is derived from a query that contains the id, and name. It displays the name but is bound to the id, can this have anything to do with the error? >

Yes that is where the error is coming from

use this


    strSQL = "UPDATE tblEmployees SET strEmpPassword ='" & Me.txtNewPassword & "' WHERE lngEmpID =" &  Me.cboEmployee.Value  & " and strEmpPassword ='" & Me.txtOldPassword & "';"

and you may not need this part

and (strEmpPassword) ='" & Me.txtOldPassword & "';"


so just use

 strSQL = "UPDATE tblEmployees SET strEmpPassword ='" & Me.txtNewPassword & "' WHERE lngEmpID =" &  Me.cboEmployee.Value




.
0
 

Author Comment

by:ernie_shah
ID: 39674361
Great, it was a success.

Thanks very much!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question