If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Search and compare data in a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-12, 08:36
ednis ednis is offline
Registered User
 
Join Date: Aug 2012
Posts: 8
Red face Search and compare data in a table

Could someone help me with the project Im doing. Basically I got a form, and that form has textbox. When I enter my ID or someone enters their ID then click on the command button. It will check each data in a certain field in a table.

here is what I currently have:

Private Sub LookUp_Click()

Dim db As Database
Dim rs As DAO.Recordset


Set db = CurrentDb
Set rs = db.Recordsets("Login")

rs.FindFirst ("[vzid]")

Do While Not (rs.EOF)

If rs![vzid] = Me.InputT.Value Then

TimeIn.Visible = True
TimeOut.Visible = True

Else

rs.MoveNext

End If

Loop


End Sub
Reply With Quote
  #2 (permalink)  
Old 08-10-12, 10:31
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 4,153
This is not the proper way of using the FindFirst method. Try:
Code:
Private Sub LookUp_Click()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strCriteria As String
    
    strCriteria = "vzid = " & Me.InputT.Value
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Login", dbOpenSnapshot)
    rs.FindFirst strCriteria
    If rs.NoMatch = False Then
        TimeIn.Visible = True
        TimeOut.Visible = True
    End If
    rs.Close
    Set rs = Nothing

End Sub
Ideally, you should test for a Null in InputT before performing the search.
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 08-10-12, 13:10
ednis ednis is offline
Registered User
 
Join Date: Aug 2012
Posts: 8
Thanks. I tried the code but im getting a yellow line at

rs.FindFirst strCriteria

vzid for example is x1234

I can't see why this is giving me an error.
Reply With Quote
  #4 (permalink)  
Old 08-10-12, 15:49
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 4,153
Quote:
Originally Posted by ednis View Post
Thanks. I tried the code but im getting a yellow line at

rs.FindFirst strCriteria

vzid for example is x1234

I can't see why this is giving me an error.
Because if vzid is defined as Text, you must use:
Code:
strCriteria = "vzid = '" & Me.InputT.Value & "'"
__________________
Have a nice day!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On