finding a record in a table
finding a record in a table
(OP)
I have a database where a user inputs a password and I check the table record to see if it is there to grant them access to the forms. This is the code I am using but it only finds the first record in the table. I want it to search the whole column.
Dim db As Database, rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("users", dbOpenTable)
Key = rs.Fields("password").Value
Password = InputBox("Enter your password")
If Password = Key Then
MsgBox ("this Works")
else
msgbox("Wrong Password")
Can someone please help me, Thank You Travis
RE: finding a record in a table
Key = rs.Fields("password") or
Key = rs!password or
Key = rs.Fields("password").Text
Not
Key = rs.Fields("password").Value
Good luck!
RE: finding a record in a table
Try this instead:
Dim db As Database, rs As Recordset
Set db = CurrentDb
Password = InputBox("Enter your password")
Set rs = db.OpenRecordset("users", dbOpenTable)
rs.FindFirst "password = '" & Password & "'"
If rs.NoMatch Then
MsgBox "Wrong Password"
Else
MsgBox "This Works"
End If
rs.Close
Set rs = Nothing
Set db = Nothing
FindFirst searches the data for the first row that matches your search criteria. If it doesn't find any row, NoMatch will be True.
I should warn you, though, that this is pretty weak security. If a user can get to the Database Window, he/she can see all the passwords.
Rick Sprague