<p><font face="Verdana">Find 方法范例 (VB)</font></p><font face="Verdana">
<p><br/>本范例使用 Recordset 对象的 Find 方法来定位 Pubs 数据库中的业务标题,并对其进行
计数。本范例假设基本提供者不支持相似的功能。</p>
<p><br/>Public Sub Main()<br/> FindX<br/>End Sub</p>
<p>Public Sub FindX()<br/>Dim cnn As New ADODB.Connec
tion<br/>Dim rst As New ADODB.Recordset<br/>Dim mark As Variant<br/>Dim count As Integer</p>
<p>count = 0<br/>cnn.Open "DSN=Pubs; Provider=MSDASQL; uid=sa; pwd=;"<br/>rst.Open "SELECT title_id FROM titles", cnn, _<br/> adOpenStatic, adLockReadOnly, adCmdText</p>
<p>' The default parameters are sufficient to search forward<br/>' through a Recordset.</p>
<p>rst.Find "title_id LIKE 'BU%'"</p>
<p>' Skip the current record to avoid finding the same row
repeatedly.<br/>' The bookmark is redundant because Find searches from the current<br/>' position.</p>
<p>Do While rst.EOF <> True 'Continue
IF last find succeeded.<br/>
debug.Print "Title ID: "; rst!title_id<br/> count = count + 1 'Count the last title found.<br/> mark = rst.Bookmark 'Note current position.<br/> rst.Find "title_id LIKE 'BU%'", 1, adSearchForward, mark<br/>Loop</p>
<p>rst.Close<br/>cnn.Close<br/>Debug.Print "The number of business titles is " & count</p>
<p>End Sub</p>
<p></font> </p>