这段代码过滤数据有什么问题?

时间:2012-03-13 09:19:09

标签: ms-access-2007 access-vba

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

上面是我试图根据用户输入到文本框中来过滤表单上的数据的代码。绝对不会发生。

1 个答案:

答案 0 :(得分:1)

您需要文字字段的引号。

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