property Grid.DetectAddNew as Boolean
Specifies whether the control detects when a new record is added to the bounded recordset.

TypeDescription
Boolean A boolean expression that indicates whether the control detects when a new record is added to the bounded recordset.

By default, the DetectAddNew property is False. The DetectAddNew property detects adding new records to a recordset. Use the DataSource property to bound the control to a table. If the DetectAddNew property is True, and user adds a new record to the bounded recordset, the control automatically adds a new item to the control  ( ADO, ADODB recordset only ). The /COM version of the component provides the DataSource property, which can be used to bound the control's view to a DAO recordset. By default, once you set the DataSource property to a recordset, all changes you do on the control will be updated in the associated recordset. Because the DAO object does not provide any notifications or events the control is not able to detect any AddNew or Delete method that has been called. Instead, the control provides the AddItem and RemoveItem events that notifies your application once a new item is added to the control, or when an item is deleted. Based on these events, you will be able to manipulate the DAO recordset appropriate as in the following samples. In addition, the control fires the Error event in case any error occurs when handling the ADO or DAO recordsets, For instance, trying to update a read-only field.  In conclusion, if user changes a cell/value in the control, the associated field in the recordset is automatically updated. If any error occurs on updating the associated record, the Error event is fired which describes the error.

Handling the AddNew method in the control, using the DAO recordset on MS Access

The code binds the control to a DAO recordset. Please notice, that the DetectAddNew property is set after calling the DataSource method. Setting the DetectAddNew property on True, makes the control associate new items with new records added during the AddItem event as shown bellow.

Private Sub cmdAddNew_Click()
    With Grid1.Items
        .EnsureVisibleItem .AddItem
    End With
End Sub 

The code adds a new item to the control and ensures that the new item fits the control's client area. The Items.AddItem call makes the control to fire the AddItem event, which will actually add the new record to the database, as in the following code

The code adds a new record to the bounded recordset. Here you need to insert or update the required fields so the new record is added to the DAO recordset. Once the event is finished, the new item is associated with the new record in the database, so from now on, any change to the item will be reflected in the recordset.

Handling the AddNew method in the control, using the ADO recordset in VB

The code binds the control to an ADO recordset.

Private Sub cmdAddNew_Click()
    With Grid1.DataSource
        .AddNew Array("FirstName", "LastName"), Array("new", "new")
        .Update
    End With
End Sub 

The code adds a new record to the attached recordset, and the control will add a new associated item, because the DetectAddNew method is True.