我在搜索按钮上运行此代码时遇到此错误。以下是我的代码。谢谢。
Option Compare Database
Option Explicit
Private Sub txtsearch_Click()
If IsNull(Searchbar) = False Then
Me.Recordset.FindFirst "[PONumber]=" & Searchbar
Me!Searchbar = Null
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!Searchbar = Null
End If
End If
End Sub
答案 0 :(得分:1)
您必须保留记录集:
Private Sub txtsearch_Click()
Dim rs As DAO.Recordset
If IsNull(Me!Searchbar.Value) = False Then
Set rs = Me.RecordsetClone
rs.FindFirst "[PONumber]=" & Me!Searchbar.Value
If rs.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Else
Me.Bookmark = rs.Bookmark
End If
Me!Searchbar.Value = Null
End If
Set rs = Nothing
End Sub