Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding a record in a table 1

Status
Not open for further replies.

Travis33

Programmer
Nov 20, 2000
31
0
0
US

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
 
if password is a text field you should have:
Key = rs.Fields("password") or
Key = rs!password or
Key = rs.Fields("password").Text
Not
Key = rs.Fields("password").Value

Good luck!
 
When you open the recordset, Access retrieves the first row for you. That's why your statement only gets the first row. You're not searching the table at all.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top