-
Hi, I have a form in my project and what it does is change the passwords in the database for users. Firstly, at the top of the form is a DBCombo box (DBAccounts) which lets the user select there username. Second is a text box(TxtPword(0).text) that the user is asked to enter in there current password. The 3rd (TxtPword(1).text)and 4th textbox(TxtPword(2).text) is for the new password they wish to input. The third and 4th textbox must equal each other before the user can update his/her password (like a verification check). Now my problem is I can't get txtpword(0).text which is the password from the database to match the user in the DBCombo box. I can get the user's names up in the DBCombo box. Now here is the code I am using to update the user's password :
Private Sub UpdatePassword()
Dim Ans As String, mRrstrans As Recordset
DatAccounts.Recordset.FindFirst ("PassID = " & DBCAccounts.BoundText)
Set mRstrans = pDatabase.OpenRecordset("Password", dbOpenTable)
If TxtPword(0).Text = mRstrans!Password And TxtPword(1).Text = TxtPword(2).Text Then
mRstrans.Edit
fldname = "Password"
mRstrans.Fields(fldname).ValidateOnSet = True
mRstrans.Fields(fldname) = TxtPword(1).Text
mRstrans.Update
mRstrans.Bookmark = mRstrans.LastModified
fp.Refresh = True
Unload Me
Ans = MsgBox("Your Password Has Been Updated", vbInformation)
mRstrans.Close
Exit Sub
Else
Ans = MsgBox("Please re-type your Old and/or New Password as they don't Match.", vbCritical)
End If
End Sub
Okay, now when the user is selected with DatAccounts.Recordset.FindFirst etc it shows the primary key. My main problem is where it says mrstrans!password it only looks at the first record and uses that password. How do i change this code to make the DBCombo box and txtPword(0).text compare each other when a user is selected. This code is under a function and is called when the ok button is click after the user has entered in the old and new passwords. Any hel would be much appreciated. Thanx in advance.
Mike
-
Hi,
When I tried your code, I was getting a whole bunch of errors.
Now, I am assuming the PassID is defined as string(or text whichever db you are using) therefore you have to enclose the DBCAccounts.BoundText in quotes:
DatAccounts.Recordset.FindFirst ("PassID = '" & DBCAccounts.BoundText & "'")
I was getting some more errors, but I need more information about what your objects are defined as like DatAccounts. It might be that you are using the wrong objects to search for your records.
Hope this helps,
Preeti
-
Nah, PassID is the primary key and th datAccounts isn't the problem. The problem is to do with the TxtPword(0).text. If the user selects out of the dbcombo box a user call bob then i want the TxtPword(0).text to equal the password in the database for Bob. SO when they type in there old password in TxtPword(0).text then it will agree with the database therefore enabling the user to change there password in TxtPword(1).text.
Mike
-
Hi,
It makes no difference if PassID is a primary key, what matters is it's datatype. Your findfirst statement was wrong and I corrected if for you. When you are looking for the PassID in the right way, then you will get Password for the selected PassID. The reason that I am not sure if this is your only problem is because I was getting too many error in guessing what you declared your objects as to access your database.
Also, this line:
Set mRstrans = pDatabase.OpenRecordset("Password", dbOpenTable)
Opens the whole table, not a subset of the table. Maybe this is the problem. You do not search for the right record but automatically look at the first record assuming this is the record that you want. If Password is a full table and not a query etc... Then using mRstrans, you first need to search for the record that you want. The one associated with the PassID selected.
Preeti