?
Solved

Changing User Password

Posted on 2013-11-22
6
Medium Priority
?
427 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 2000 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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 2000 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

765 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