Solved

Changing User Password

Posted on 2013-11-22
6
412 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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 119

Expert Comment

by:Rey Obrero
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 119

Accepted Solution

by:
Rey Obrero 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now