Microsoft KB Archive/223066

= FIX: Placing MsgBox in SelChange Event of DataGrid Causes IPF =

Article ID: 223066

Article Last Modified on 11/4/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q223066



SYMPTOMS
A Msgbox function placed in the SelChange event for a DataGrid causes a run-time Application Error that terminates Visual Basic.

Using Windows NT, you get the following error:

The instruction at "0x24ce5280" referenced memory at "0x000c0158". The memory could not be "read".

Click OK to terminate the application.

Click on CANCEL to debug the application.

Using either Windows 95 or Windows 98, you get this error:

VB6 caused an invalid page fault in module MSDATGRD.OCX at 0137:24ec5280.



CAUSE
This bug occurs if a record selector is clicked while the DataGrid's internal edit mode is set to True. You can explicitly set the internal edit mode to True, using DataGrid.EditActive = True. In addition, the internal edit mode can be set to True implicitly, by changing the focus. The MsgBox function causes a change of focus.



RESOLUTION
This behavior no longer occurs with the version of the DataGrid that ships with Visual Basic 6.0 Service Pack 3.



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

This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed



MORE INFORMATION
A record selector is the rectangle to the left of each row of a DataGrid. When clicked, a record selector selects an entire row of the DataGrid. Clicking a record selector raises the SelChange event of the DataGrid.

Steps to Reproduce Behavior
 Create a new Standard EXE. From the Projects menu, choose Components and select Microsoft ADO Data Control 6.0 and Microsoft DataGrid Control v6.0. Place an ADODC and a DataGrid on the form. Set up the ConnectString for the ADODC by pressing the ellipsis, and selecting the OLE DB Provider for SQL Server. Choose the other items that are appropriate for your system. You should then have a ConnectString that looks like the following:

Note The User ID must have the appropriate permissions to perform these operations.

ConnectionString: Provider=SQLOLEDB.1;Persist Security Info=False;User ID= ;Initial Catalog=pubs;Data Source=yourserver

 Set the RecordSource property to "Select * from Authors".</li> Set the DataSource property of the DataGrid to ADODC1.</li> In the code window for the form, select Datagrid1 in the first drop-down combo box and Selchange in the second drop-down combo box. This places the DataGrid1_SelChange event into the code window.</li>  Place the following code in this event: MsgBox "SelChange event raised" </li> Run the form. Click on the record selector for a record. The message box displays. Click OK. In the DataGrid, a field is highlighted for editing.</li> Click on the record selector for a different record, or anywhere else in the DataGrid, and you will get the Application Error message box with the error shown in the SYMPTOMS section.</li></ol>

Keywords: kbbug kbfix kbvs600sp3fix KB223066

-

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

© Microsoft Corporation. All rights reserved.