FindFirst not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    FindFirst not working

    I have used findfirst for ages without problems

    Here is a snippet of code
    Code:
                    ' Check if the word has been translated
                    If WordNo = 4 And LanguageID = 2 Then Stop
                    
                    Criteria = "[WordNo] = " & CLng(WordNo) & " AND [LanguageID] = " & CLng(!LanguageID)
                    WordSet.MoveLast
                    WordSet.MoveFirst
                    WordSet.FindFirst Criteria
                    If WordSet.NoMatch Then                                 ' Not yet translated
                        TranslatedWordNotFound = -1
                        GoTo TranslateIt
                    End If
    I can see the correct line in the query that this criteria is is searching for.

    If the criteria is Word = 2 and Language = 4 it works

    I have tried with & without the MoveLast & MoveFirst before applying the Criteria

    I have tried with & without square brackets

    I have tried with & without CLng

    I am at a complete loss. Grateful for a soluion

    Thanks

    Phil
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    Phil,
    Have you tried adding single quotes around your values instead of trying to interpret them as integers?

    Code:
    Criteria = "[WordNo] = '" & WordNo & "' AND [LanguageID] = '" & LanguageID & "'"

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      Are you getting an error? What happens when "it doesn't work"?

      Comment

      • PhilOfWalton
        Recognized Expert Top Contributor
        • Mar 2016
        • 1430

        #4
        Thanks for coming Back.

        Both WordNo & LanguageID are long integers and come straight from the Table TblWords.

        Thee is no error, the .FindFirst just doesn't find the record. The .NoMatch is True

        The only other thing that might have something to do with it is that
        all the tables are linked into the main database, and the routine that throws the error is in a Library database. Perhaps I am seeing the table, but the routine is not. If so, why should it work for some values?

        Phil

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          You may be suffering with order of precedence of operators. Don't forget AND is a Boolean operator that acts on numeric values.

          Try :
          Code:
          Criteria = "([WordNo] = " & CLng(WordNo) & ") AND ([LanguageID] = " & CLng(!LanguageID) & ")"
          Or make it more readable by using Replace() but the result should be the same.

          Comment

          • PhilOfWalton
            Recognized Expert Top Contributor
            • Mar 2016
            • 1430

            #6
            Just to say thanks for your input but the problem turned out to be tables in different databases and Access (or me getting confused)

            Phil

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Good to hear you have it sorted anyway :-)

              Comment

              Working...