Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    8

    Red face Unanswered: 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

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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!

  3. #3
    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.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •