0

我在 Access 2007 中有一个数据库,我目前正在为文本搜索框使用以下代码。我的问题是,如果在搜索框中输入了整个名称,它只会找到记录。对于企业名称,我希望用户能够输入企业的第一个单词并检索表单上的记录。目前,如果我输入名字,它会说找不到记录。我必须输入整个公司名称。有人可以帮我根据需要调整此代码吗?

私有子 txtsrch_AfterUpdate()

If (txtsrch & vbNullString) = vbNullString Then Exit Sub
    Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[lastname]=""" & txtsrch & """"
If rs.NoMatch Then
    MsgBox "Sorry, no such record '" & txtsrch & "' was found.", _
           vbOKOnly + vbInformation
Else
    Me.Recordset.Bookmark = rs.Bookmark
End If
rs.Close
txtsrch = Null

结束子

谢谢你。

4

1 回答 1

0

你可以:

rs.FindFirst "[lastname] Like '*" & Replace(txtsrch,"'","''") & "*'"

您可以更改以 txtsrch 开头、以 txtsrch 结尾的通配符(* 表示 DAO)的放置位置,或者如图所示,名称中包含 txtsrch。

于 2012-03-06T15:00:24.120 回答