Dear All,
This query is related to MSAccess-Forms-VBA coding to adding new records in to a table using recordset.
For example, I have a table named as 'Table1' with fields F1, F2, F3, F4. In the Form, I have four TextBoxs named as txtF1, txtF2, txtF3, txtF4. I have a Command button named as 'Command19'.
I would like to insert a record into the 'Table1'. I want to use a loop to add the values from TextBoxes to the Fields in the 'Table1'. I want to loop so that I can insert more data.
Here is the code I had written. Can anyone help what code can be used in the place of 'XXXXXXXXX' in the following command button.
Thanks in advance for the kind helpers.
Regards,
M
This query is related to MSAccess-Forms-VBA coding to adding new records in to a table using recordset.
For example, I have a table named as 'Table1' with fields F1, F2, F3, F4. In the Form, I have four TextBoxs named as txtF1, txtF2, txtF3, txtF4. I have a Command button named as 'Command19'.
I would like to insert a record into the 'Table1'. I want to use a loop to add the values from TextBoxes to the Fields in the 'Table1'. I want to loop so that I can insert more data.
Here is the code I had written. Can anyone help what code can be used in the place of 'XXXXXXXXX' in the following command button.
Code:
Private Sub Command19_Click()
Dim DBSS As Database, RSTT As Recordset, STRSQLL As String, Table1 As TableDef
Set DBSS = CurrentDb
STRSQLL = "SELECT * FROM Table1;"
Set RSTT = DBSS.OpenRecordset(STRSQLL)
With RSTT
I = 1
For I = 1 To 4
.AddNew
!'XXXXXXXXX'= Me("txtCh" & I)
.Update
Next I
End With
End Sub
Regards,
M
Comment