FindFirst criteria for multiple fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziccardi
    New Member
    • Mar 2010
    • 12

    FindFirst criteria for multiple fields

    I'm trying to update a table with information from another table. The tables have 4 fields that should match to allow the update.

    Here is the code that is giving me a problem:
    Code:
    With UpdtTrends
                        .FindFirst ("[FNU]=" & MyTrend!FNU & " AND " & _
                        "[TrendCat_CK]=" & MyTrend!trend_cat_CK & " AND " & _
                        "[Trend_From_Dt]=" & MyTrend!trend_from & " AND " & _
                        "[Trend_To_Dt]=" & MyTrend!trend_to)
                            If Not .NoMatch Then
                                .Edit
                                UpdtTrends!Trend_Fctr = MyTrendCat
                                UpdtTrends.Update
                                MyTrend.MoveNext
    I don't get an error - it just doesn't find the match in my table (which I know exists).
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    The first thing I think about when no match is found but I know there really is a match is
    "Does an argument on one side of the equation contain trailing spaces and the argument on the other side doesn't ?

    If "Test " = "Test"

    evaluates to false even though when you look at the data in a table it appears as though they should match.

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      Im guessing that [Trend_From_Dt] and [Trend_To_Dt] contains date fields?

      If that is the case you need to enclose the date literals your parsing in the string in #

      Code:
      With UpdtTrends
      .FindFirst ("[FNU]=" & MyTrend!FNU & " AND " & _
      "[TrendCat_CK]=" & MyTrend!trend_cat_CK & " AND " & _
      "[Trend_From_Dt]=#" & MyTrend!trend_from & "# AND " & _
      "[Trend_To_Dt]=#" & MyTrend!trend_to & "#")
      If Not .NoMatch Then
      .Edit
      UpdtTrends!Trend_Fctr = MyTrendCat
      UpdtTrends.Update
      MyTrend.MoveNext

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        that looks like a good guess

        Comment

        • ziccardi
          New Member
          • Mar 2010
          • 12

          #5
          Thank you so much - problem solved!

          Comment

          Working...