Append data from several tables to one table (1 Viewer)

AlSallam

New member
Local time
Today, 06:42
Joined
Nov 29, 2013
Messages
4
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:42
Joined
Aug 30, 2003
Messages
36,125
You forgot the MoveNext on the from recordset and created an endless loop.
 

AlSallam

New member
Local time
Today, 06:42
Joined
Nov 29, 2013
Messages
4
You are right thank you
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:42
Joined
Aug 30, 2003
Messages
36,125
Happy to help.
 

Users who are viewing this thread

Top Bottom