Insert Into Statement (1 Viewer)

Gorio

Registered User.
Local time
Today, 01:33
Joined
Sep 26, 2000
Messages
33
I want to insert 3 fields from one table to another using code.

Old Table = "Current"
New Table = "Utilization"

Fields = Index, Date, Time

This is causing poblems due to a
Compile error
Expected : end of statement

Dim db As Database


db.Execute INSERT INTO Utilization (Index, Date, Time) SELECT Index, Date, Time FROM Current

I've never tried anything like this and am not sure what I am missing. Any help or direction is appreciated
 
R

Rich

Guest
Yoy might find it easier to create an append query test it and then paste the resulting SQL statement.
 

Robert Saye

Registered User.
Local time
Yesterday, 20:33
Joined
Jun 19, 2000
Messages
49
Hello,

Try something like this:

Public Sub Test()

DoCmd.RunSQL ("INSERT INTO table3 (1,2,3) SELECT tblActionItem.ActionItem, tblActionItem.SerialNumberID, tblActionItem.ActionItemID " _
& "FROM tblActionItem;")

End Sub

This worked for me.
The underline is Access's way to continue a single line on a new line. So on the page my code is actually only 2 lines so one break...
Also you need quotes around your SQL statement.
HTH
Robert

[This message has been edited by Robert Saye (edited 05-22-2001).]
 

Gorio

Registered User.
Local time
Today, 01:33
Joined
Sep 26, 2000
Messages
33
That got it working Robert. Thanks.

However, can you enlighten me as to the difference of using:
db.Execute or DoCmd.RunSQL ?

Which method is proper? Advantages? Disadvantages?
 

Users who are viewing this thread

Top Bottom