Microsoft KB Archive/223062

= FIX: DataGrid Will Not Add a New Record if Fields Set in Code =

Article ID: 223062

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q223062



SYMPTOMS
Rows will not be added to an ADO Data Control's Recordset if the field values are set programmatically in the OnAddNew event of the DataGrid.



CAUSE
This behavior was due to a bug in the DataGrid Control (msdatgrd.ocx).



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



Steps to Reproduce Behavior
This code uses the Biblio database that comes with Visual Basic.  Start Visual Basic 6.0 and create a new EXE project. Form1 is added by default.  Add the following two controls to the default form: Microsoft ADO Data Control 6.0 (OLEDB) Microsoft DataGrid Control 6.0 (OLEDB)   Set the properties of the ADO Data Control, ADODC1, as follows: ConnectionString Provider=Microsoft.Jet.OLEDB.3.51;DataSource= C:\ProgramFiles\Microsoft Visual Studio\VB98\Biblio.mdb RecordSource "SELECT * FROM Authors"   Set the properties of the DataGrid, DataGrid1, as follows: DataSource       ADODC1 AllowAddNew      True TabAction        2-dbgGridNavigation </li>  Add following code to the default form: Private Sub DataGrid1_OnAddNew DataGrid1.Columns("Author").Text = "Test" DataGrid1.Columns("Year Born").Text = 1996 End Sub </li> Run the project. Go to the last record in the DataGrid (the blank row) and click on any cell. The second and third columns will have the default values "Test" and "1999" entered. Continue tabbing through the cells so that the new record gets updated.</li> End the program, and then run again. Note that the new row has not actually been added.</li></ol>

Keywords: kbbug kbfix kbdatabinding kbdatabase kbctrl kbvs600sp3fix KB223062

-

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

© Microsoft Corporation. All rights reserved.