×
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

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!

RE: finding a record in a table

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

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