JPaulo
Developer
- Local time
- Today, 11:40
- Joined
- Dec 21, 2009
- Messages
- 185
Hi all;
My table in 100 fields and did not want to copy 100 times the INSERT INTO.
It aims to do for all 100 fields, with only one line of INSERT INTO ?
My table in 100 fields and did not want to copy 100 times the INSERT INTO.
It aims to do for all 100 fields, with only one line of INSERT INTO ?
Code:
Private Sub MyButton_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = CurrentDb.OpenRecordset("Select * from tblSample ORDER BY ID ASC")
Do Until rst.EOF
CurrentDb.Execute "INSERT INTO [temp] (X,Y) VALUES ('" & rst.Fields(0).Name & "','" & rst.Fields(0) & "')"
CurrentDb.Execute "INSERT INTO [temp] (X,Y) VALUES ('" & rst.Fields(1).Name & "','" & rst.Fields(1) & "')"
CurrentDb.Execute "INSERT INTO [temp] (X,Y) VALUES ('" & rst.Fields(2).Name & "','" & rst.Fields(2) & "')"
CurrentDb.Execute "INSERT INTO [temp] (X,Y) VALUES ('" & rst.Fields(3).Name & "','" & rst.Fields(3) & "')"
CurrentDb.Execute "INSERT INTO [temp] (X,Y) VALUES ('" & rst.Fields(4).Name & "','" & rst.Fields(4) & "')"
rst.MoveNext
Loop
Set rst = Nothing
MsgBox "Successfully added..."
End Sub