Problem with "Findfirst"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alinagoo
    New Member
    • Apr 2010
    • 53

    Problem with "Findfirst"

    Hi all
    I'm a beginner in Recordsets so i have a problem with Recordsets!
    When my application runs followed code,Run-Time Error '3070' occurs!
    What is the problem?
    Is there any wrong statement?

    Thanks in advanced

    Code:
    Sub findrecord_bypkgno()
        Dim rst As DAO.Recordset
        Dim strCriteria As String
    
        strCriteria = "[Pack_no]= " & Me.searchpkg
        Set rst = Me.RecordsetClone
        rst.FindFirst (strCriteria)   'Run time error's yellow ribbon appear here
        If rst.NoMatch Then
            MsgBox "No entry found.", vbInformation
        Else
            Me.Bookmark = rst.Bookmark
        End If
    
        Set rst = Nothing
    
    End Sub
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Since I don't know all the error codes by heart (thats my impolite way of saying please remember to post the full error description) I can only guess.

    I think you simply need to remove the ( and ) around strCriteria.
    If that doesn't work, make sure your giving it a proper strCriteria. Write a Msgbox strCriteria line into your code, before the Findfirst, so you can check that the strCriteria looks like its supposed to.

    Also:
    Is Pack_no a numeric value?

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Code:
      Dim rst As DAO.Recordset
      Dim strCriteria As String
        
      strCriteria = "[Pack_no]= '" & Me.searchpkg & "'"
      
      Set rst = Me.RecordsetClone
      
      rst.FindFirst (strCriteria)
      
      If rst.NoMatch Then
        MsgBox "No entry found.", vbInformation
      Else
        Me.Bookmark = rst.Bookmark
      End If
       
      rst.Close
      Set rst = Nothing

      Comment

      • alinagoo
        New Member
        • Apr 2010
        • 53

        #4
        Thanks so That worked !

        Comment

        • alinagoo
          New Member
          • Apr 2010
          • 53

          #5
          Thanks
          This is the solution:
          strCriteria = "[Pack_no]= '" & Me.searchpkg & "'"

          Comment

          Working...