Solved

Changing User Password

Posted on 2013-11-22
6
423 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
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

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

Suggested Solutions

Title # Comments Views Activity
VBA to copy the database back end to a new database file. 3 34
Delete QueryDef IF it Exists: Access VBA 5 35
Binding recordsets to a form 6 24
Modify report 7 3
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

773 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