在打开的记录集下如何再进行检索操作,先前在程序启动时已打开了记录(ADORS.OPEN "SELECT *........),程序中加一检索功能按钮要执行查询操作当如何处理,用什么语句,如果再OPEN记录集的话程序是会报错的。请各位指教!

解决方案 »

  1.   

    使用Filter方法在已经存在的记录集中返回符合条件的记录
    即二次过滤的例子Public Sub FilterX()   Dim rstPublishers As ADODB.Recordset
       Dim rstPublishersCountry As ADODB.Recordset
       Dim strCnn As String
       Dim intPublisherCount As Integer
       Dim strCountry As String
       Dim strMessage As String   ' Open recordset with data from Publishers table.
       strCnn = "Provider=sqloledb;" & _
          "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
       Set rstPublishers = New ADODB.Recordset
       rstPublishers.CursorType = adOpenStatic
       rstPublishers.Open "publishers", strCnn, , , adCmdTable   ' Populate the Recordset.
       intPublisherCount = rstPublishers.RecordCount   ' Get user input.
       strCountry = Trim(InputBox( _
          "Enter a country to filter on:"))   If strCountry <> "" Then
          ' Open a filtered Recordset object.
          Set rstPublishersCountry = _
             FilterField(rstPublishers, "Country", strCountry)      If rstPublishersCountry.RecordCount = 0 Then
             MsgBox "No publishers from that country."
          Else
             ' Print number of records for the original
             ' Recordset object and the filtered Recordset
             ' object.
             strMessage = "Orders in original recordset: " & _
                vbCr & intPublisherCount & vbCr & _
                "Orders in filtered recordset (Country = '" & _
                strCountry & "'): " & vbCr & _
                rstPublishersCountry.RecordCount
             MsgBox strMessage
          End If
          rstPublishersCountry.Close   End IfEnd SubPublic Function FilterField(rstTemp As ADODB.Recordset, _
       strField As String, strFilter As String) As ADODB.Recordset   ' Set a filter on the specified Recordset object and then
       ' open a new Recordset object.
       rstTemp.Filter = strField & " = '" & strFilter & "'"
       Set FilterField = rstTempEnd Function