manthiralaya
Registered User.
- Local time
- Today, 22:52
- Joined
- Oct 14, 2010
- Messages
- 13
Hi,
This query is related to MSAccess-Forms-VBA coding to adding new records in to a table using recordset.
Say 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. It gives an error of "Item not found in this collection". What am I doing wrong? Can anyone help?
Private Sub Command19_Click()
Dim DBSS As Database, RSTT As Recordset, STRSQLL As String, Table1 As TableDef, fldVar As Field
Set DBSS = CurrentDb
STRSQLL = "SELECT * FROM Table1;"
Set RSTT = DBSS.OpenRecordset(STRSQLL)
With RSTT
I = 1
For I = 1 To 4
.AddNew
!fldVar("F" & I) = Me("txtF" & I)
.Update
Next I
End With
End Sub
Thanks in advance for your kind help.
Regards,
Manthiralaya
This query is related to MSAccess-Forms-VBA coding to adding new records in to a table using recordset.
Say 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. It gives an error of "Item not found in this collection". What am I doing wrong? Can anyone help?
Private Sub Command19_Click()
Dim DBSS As Database, RSTT As Recordset, STRSQLL As String, Table1 As TableDef, fldVar As Field
Set DBSS = CurrentDb
STRSQLL = "SELECT * FROM Table1;"
Set RSTT = DBSS.OpenRecordset(STRSQLL)
With RSTT
I = 1
For I = 1 To 4
.AddNew
!fldVar("F" & I) = Me("txtF" & I)
.Update
Next I
End With
End Sub
Thanks in advance for your kind help.
Regards,
Manthiralaya