简体   繁体   中英

What's wrong with this code for filtering data?

Private Sub txtSearchJobNo_AfterUpdate()
Dim rst As DAO.Recordset, strCriteria As String
strCriteria = "[A_JOBNO]=" & txtSearchJobNo
Me.FilterOn = False
'-- Me.Filter = strCriteria
Me.FilterOn = True
Set rst = Me.RecordsetClone
rst.FindFirst(strCriteria"[A_JOBNO]=" & txtSearchJobNo)
If rst.NoMatch Then
MsgBox "No entry found"
Else
Me.Bookmark = rst.Bookmark
End If
End Sub

Above is the code I am trying to use for filtering data on my form based on the input from the user into a textbox.Nothing absolutely happens.

You need quotes for text fields.

Private Sub txtSearchJobNo_AfterUpdate()
   Dim rst As DAO.Recordset, strCriteria As String

   strCriteria = "[A_JOBNO]=" & txtSearchJobNo
   Set rst = Me.RecordsetClone
   rst.FindFirst(strCriteria"[A_JOBNO]='" & txtSearchJobNo) & "'"

   If rst.NoMatch Then
      MsgBox "No entry found"
   Else
      Me.Bookmark = rst.Bookmark
     'Filter here or bookmark, not both
   End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM