2012-03-13 30 views
1
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 

以上是我试图用来过滤基于用户输入到文本框中的表单上的数据的代码。没有什么绝对会发生。此代码用于过滤数据有什么问题?

+0

您确定A_JobNo是数字字段吗?顺便说一句,你使用过滤器和发现不是一个好主意。 – Fionnuala 2012-03-13 09:32:40

+0

A_JobNo是sql db中的nvarchar(15),存储如下所示的值:“E2Y9038”,而在表单中它被选为“E-2Y-9038”以显示在窗体上。在调试时也是第一个.NoMatch = false。那么更好的方法是什么? – user1175126 2012-03-13 09:56:23

+0

这是你的问题。 – Fionnuala 2012-03-13 10:04:24

回答

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