BUG: ADO Recordset Filter Is Removed After You Set Sort Property (313204)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 1.0
  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.01
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q313204

SYMPTOMS

If you set the filter property of an ADO recordset to an array of bookmarks and subsequently set the sort property, the filter is removed. In addition, all records are visible again in the recordset.

RESOLUTION

To work around this problem, sort the data in the query that is used to open the recordset.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Data Project in Visual Basic. The frmDataEnv form is created by default.
  2. Place a Button control on frmDataEnv.
  3. Add the following code to the button's Click event:
      Dim oCn As New ADODB.Connection
      Dim oRs As New ADODB.Recordset
      
      oCn.Open "provider=sqloledb;data source=(local);user id=me;initial catalog=northwind;"
      oRs.CursorLocation = adUseClient
      oRs.Open "SELECT * from Shippers", oCn
      
      oRs.Filter = Array(oRs.Bookmark)
      MsgBox oRs.RecordCount
      
      oRs.Sort = "CompanyName ASC"
      MsgBox oRs.RecordCount
      
      oRs.Close
      oCn.Close
      
      Set oRs = Nothing
      Set oCn = Nothing
    					
  4. Run the project, and click the button. The first message box, which displays the record count after the filter is applied, correctly displays 1.
  5. Click OK to dismiss the first message box. The next message box, which displays the original number of records, incorrectly displays 4. Notice that the filter has been removed.

Modification Type:MajorLast Reviewed:12/14/2001
Keywords:kbbug kbDSupport KB313204