Solved

Changing User Password

Posted on 2013-11-22
6
425 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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