Nihita Goel
April 4th, 2001, 06:57 AM
I am trying to develop an Input screen using DBGrid and ADO Control.I have additional Add and a Save button on my form. The functionality is such that when the user presses "Add", a new blank row appears as the last row in the Grid. Here the user can enter a new record. However, these changes should be reflected in the database only after the user presses "save" button. Also, I do NOT want the user to be able to update the existing records.
The ADO Control's RecordSource property has been set at design time only.
The code for FormLoad and Add button is like this
Private Sub Form_Load()
DataGrid1.AllowUpdate = False
DataGrid1.AllowAddNew = True
End Sub
Private Sub cmdAdd_Click()
On Error GoTo AddErr
Adodc1.Recordset.MoveLast
Adodc1.Recordset.AddNew
DataGrid1.SetFocus
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Problem is - This way the user cannot enter any data in the empty row of the grid ( since AllowUpdate is False )If I set this to true the user would be able to edit existing records which I do not want.
Second problem is - this way blank record is getting added in the database which should not be the case.All changes made in the grid should be reflected in the database on pressing "Save" button only
The ADO Control's RecordSource property has been set at design time only.
The code for FormLoad and Add button is like this
Private Sub Form_Load()
DataGrid1.AllowUpdate = False
DataGrid1.AllowAddNew = True
End Sub
Private Sub cmdAdd_Click()
On Error GoTo AddErr
Adodc1.Recordset.MoveLast
Adodc1.Recordset.AddNew
DataGrid1.SetFocus
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Problem is - This way the user cannot enter any data in the empty row of the grid ( since AllowUpdate is False )If I set this to true the user would be able to edit existing records which I do not want.
Second problem is - this way blank record is getting added in the database which should not be the case.All changes made in the grid should be reflected in the database on pressing "Save" button only