I have the following code, the purpose of the code is that to take all rows from each table to append them into one table. However, I am testing this code with 2 tables (Table2 and Table3) each table has 2 records, when I run the code, it keeps adding records to table 1 that exceeds one million. what is wrong with my code?
Dim tblString, I As Integer
Dim rstFrom As Recordset, rst2 As Recordset
Dim db As Database
Set db = CurrentDb
Set rst2 = db.OpenRecordset("Table1", dbOpenDynaset)
tblString = Array("Table2", "Table3")
For I = 0 To 1
Set rstFrom = db.OpenRecordset(tblString(I), dbOpenDynaset)
If Not rstFrom.BOF Then
rstFrom.MoveFirst
Do Until rstFrom.EOF
With rst2
.AddNew
rst2![Field1] = rstFrom![Field1]
rst2![Field2] = rstFrom![Field2]
rst2![Field3] = rstFrom![Field3]
.Update
End With
Loop
End If
Next I
Set rst2 = Nothing
Set rstFrom = Nothing
Set db = Nothing
Dim tblString, I As Integer
Dim rstFrom As Recordset, rst2 As Recordset
Dim db As Database
Set db = CurrentDb
Set rst2 = db.OpenRecordset("Table1", dbOpenDynaset)
tblString = Array("Table2", "Table3")
For I = 0 To 1
Set rstFrom = db.OpenRecordset(tblString(I), dbOpenDynaset)
If Not rstFrom.BOF Then
rstFrom.MoveFirst
Do Until rstFrom.EOF
With rst2
.AddNew
rst2![Field1] = rstFrom![Field1]
rst2![Field2] = rstFrom![Field2]
rst2![Field3] = rstFrom![Field3]
.Update
End With
Loop
End If
Next I
Set rst2 = Nothing
Set rstFrom = Nothing
Set db = Nothing