无论是DAO还是ADO都有两种从Recordset对象中查询记录的方法:Find方法和Seek方法。在这两种方法中可以让你指定条件进行查询与其相应的记录, 一般而言,在相同条件下,Seek方法提供了比Find方法更好的性能,因为Seek方法是基于索引的。因为这个原因基本提供者必须支持 Recordset 对象上的索引,可以用Supports(adSeek) 方法确定基本提供者是否支持Seek,用Supports(adIndex) 方法确定提供者是否支持索引。(例如,OLE DB Provider for Microsoft Jet支持Seek和Index。),请将Seek方法和Index属性结合使用。如果Seek没有找到所需的行,将不会产生错误,该行将被放在Recordset 的结尾处。执行此方法前,请先将Index 属性设置为所需的索引。此方法只受服务器端游标支持。如果 Recordset对象的CursorLocation属性值为adUseClient,将不支持 Seek。只有当 CommandTypeEnum值为adCmdTableDirect 时打开Recordset对象,才可以使用此方法。
用ADO Find方法
DAO包含了四个“Find”方法:FindFirst,FindLast,FindNext和FindPrevious.
DAO方法 ADO Find 方法
下面的一个例子示范了如何用ADO Find方法查询记录:
Sub FindRecord(strDBPath As String, _
strTable As String, _
strCriteria As String, _
strDisplayField As String)
" This procedure finds a record in the specified table by
" using the specified criteria.
" For example, to use this procedure to find records