Adding Records from one Table to another (1 Viewer)

VSolano

Registered User.
Local time
Today, 01:00
Joined
Feb 21, 2017
Messages
85
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
 

plog

Banishment Pending
Local time
Today, 00:00
Joined
May 11, 2011
Messages
11,613
Define "not working". Error message? Incorrect results? No results? Your computer starts to smoke and give off sparks?

With that said, what is in the variable SQL? Is it a valid INSERT INTO statement?

https://www.w3schools.com/sql/sql_insert.asp
 

VSolano

Registered User.
Local time
Today, 01:00
Joined
Feb 21, 2017
Messages
85
It says invalid inset into statement

The SQL is just a variable to hold the expression
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 16:00
Joined
Jan 20, 2009
Messages
12,849
Use parentheses instead of brackets.
Code:
SQL = " INSERT INTO tbtaskshedule[B][COLOR=red][[/COLOR][/B]taskdescription[B][COLOR=red]][/COLOR][/B] VALUES ('" & Descr & "')"
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:00
Joined
Aug 30, 2003
Messages
36,118
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

Top Bottom