×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

finding a record in a table

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

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

RE: finding a record in a table

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close