Adding Records from one Table to another

VSolano

Registered User.
Local time
Today, 11:13
Joined
Feb 21, 2017
Messages
92
I have the following code where I am trying to copy the value of one table to another and for some reason that I can not figure out, the code is not working


Option Compare Database

Public Function taskschedule()
Dim DB As Database
Dim RS As Recordset
Dim SQL As String
Dim Descr As String


Set DB = CurrentDb
Set RS = DB.OpenRecordset("TbTask", dbOpenDynaset, dbSeeChanges)

Descr = RS!taskdescription

Do Until RS.EOF

SQL = " INSERT INTO tbtaskshedule[taskdescription] VALUES ('" & Descr & "')"


DB.Execute (SQL)

RS.MoveNext

Loop


DB.Close
RS.Close
Set RS = Nothing




End Function
 
It says invalid inset into statement

The SQL is just a variable to hold the expression
 
Use parentheses instead of brackets.
Code:
SQL = " INSERT INTO tbtaskshedule[B][COLOR=red][[/COLOR][/B]taskdescription[B][COLOR=red]][/COLOR][/B] VALUES ('" & Descr & "')"
 
Why the loop? Get them all in one go, not RBAR.

INSERT INTO tbtaskshedule(taskdescription)
SELECT taskdescription FROM tblTasks
 

Users who are viewing this thread

Back
Top Bottom