Microsoft KB Archive/191919

= BUG: DataGrid Does Not Handle Special Filter Constants Correctly =

Article ID: 191919

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 4
 * Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 5
 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7

-



This article was previously published under Q191919



SYMPTOMS
When the filter of an ADO Recordset object is set to one of the special constants, such as adFilterPendingRecords, the bound DataGrid control still displays all of the rows in the Recordset. If the filter is set to specify a particular field, such as "State = 'CA'," the DataGrid displays only the rows that are specific to that filter.



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



MORE INFORMATION
The code that follows filters based on a field and displays the appropriate data in the grid.

Modifying records in the data grid and setting the Filter property of the Recordset to display only records with pending changes (Filter = adFilterPendingRecords) causes the recordset to correctly filter on those changed records. However, the DataGrid does not correctly display the filtered Recordset object.

Steps to Reproduce the Behavior
 Create a Standard EXE project in Visual Basic. Form1 is created by default. On the Project menu, click References. In the list of available references, click Microsoft ActiveX Data Objects Library. On the Project menu, click Components. In the list of available components, click Microsoft DataGrid Control 6.0 (OLEDB). Add a DataGrid control and two CommandButton controls to Form1.</li> Set the name and the caption properties of the CommandButton controls as follows: <ul> Command1:

Name = cmdFilterField

Caption = FilterField</li> Command2:

Name = cmdFilterPending

Caption = FilterPending</li></ul> </li>  Add the following code to the General Declarations of Form1: Dim rsAuthors As New ADODB.Recordset Private Sub cmdFilterField_Click rsAuthors.Filter = adFilterNone rsAuthors.Filter = "State = 'UT'" End Sub

Private Sub cmdFilterPending_Click rsAuthors.Filter = adFilterNone rsAuthors.Filter = adFilterPendingRecords End Sub

Private Sub Form_Load Dim cnPubs As New ADODB.Connection Dim strConn As String

' You may have to change the following line ' to a valid SQL Server strConn = "Provider=SQLOLEDB;Data Source=(local);" & _ "Initial Catalog=pubs;"

cnPubs.CursorLocation = adUseClient cnPubs.Open strConn, "sa", ""

rsAuthors.Open "SELECT * FROM Authors", cnPubs, adOpenStatic, _ adLockBatchOptimistic

Set rsAuthors.ActiveConnection = Nothing

cnPubs.Close

Set DataGrid1.DataSource = rsAuthors

End Sub </li> Press the F5 key to run the application, and note the behavior of the different filter methods.</li></ol>

Keywords: kbbug kbdatabase kbctrl kbpending KB191919

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.