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!

Help with finding a record in a table

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
 
You need to use a loop:

Dim db As Database, rs As Recordset
Dim found As boolean
Set db = CurrentDb
Set rs = db.OpenRecordset("users", dbOpenTable)

found = false
Password = InputBox("Enter your password")
DO WHILE NOT rs.eof
Key = rs!password
If Password = Key Then
found = true
EXIT DO
end if
rs.movenext
LOOP
rs.close
set rs = nothing
if found then
msgbox("Password Found")
else
msgbox("Invalid Password")
end if
Mike Rohde
rohdem@marshallengines.com
 
I know it is passe to suggest this, but are you developing some home-grown security system? There must be some reason you aren't using the Access User Security. Merely setting us your application properly will provide login capabilities which require a username/password for access to the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top