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
 
You need to use the rs.movenext command in the else portion of your if statement and encompass the whole if statement in a do loop along the lines of
'Do while not rs.eof()
if statement
blah
else
blah
end if
loop

this way the process will compare key and password for each record in rs. It would be good practice to ensure you start on the first row of the record set by using rs.movefirst before the do loop.
and while we are here dont forget to set rs and db to nothing at the end of the procedure so that the memory is released
 
I think the code might look more like this:

Dim db As Database, rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("users", dbOpenTable)
rst.movefirst
While (not(rst.eof))
Key = rs.Fields("password").Value
Password = InputBox("Enter your password")
If Password = Key Then
MsgBox ("this Works")
else
msgbox("Wrong Password")
rst.movenext
Wend

because you will need to reference the password for the record each time you move to a next record.

ntp

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top