473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

"CREATE TABLE AS" (using ADODB Command Object)

I'm attempting to create a new table, and populate it using the fields
from two existing tables. The code is printed below. I get the error:
"Run-time error '-2147217900 (80040e14)': Syntax error in CREATE TABLE
statement." For what it's worth, when tested independently, the
"SELECT [...]" part of my CREATE TABLE statement works properly.

Sub test()

Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection

cmd.CommandText = "CREATE TABLE tbl1 (uid INTEGER PRIMARY KEY, foo
INTEGER)"
cmd.Execute , , adCmdText

cmd.CommandText = "INSERT INTO tbl1 (uid, foo) VALUES (1, 2)"
cmd.Execute , , adCmdText

cmd.CommandText = "CREATE TABLE tbl2 (uid INTEGER PRIMARY KEY, bar
INTEGER)"
cmd.Execute , , adCmdText

cmd.CommandText = "INSERT INTO tbl2 (uid, bar) VALUES (1, 3)"
cmd.Execute , , adCmdText

cmd.CommandText = "CREATE TABLE tbl3 AS (SELECT tbl1.[uid], tbl1.
[foo], tbl2.[bar] FROM tbl1 INNER JOIN tbl2 ON tbl1.[uid] = tbl2.
[uid])"
cmd.Execute , , adCmdText

End Sub

Jun 29 '07 #1
1 12728
You should be using SELECT INTO

This SQL will work:
SELECT
tbl1.foo,
tbl2.bar
INTO
tbl3
FROM
tbl1
INNER JOIN tbl2
ON tbl1.uid = tbl2.uid

On Jun 29, 4:35 pm, dave.j.thorn...@gmail.com wrote:
I'm attempting to create a new table, and populate it using the fields
from two existing tables. The code is printed below. I get the error:
"Run-time error '-2147217900 (80040e14)': Syntax error in CREATE TABLE
statement." For what it's worth, when tested independently, the
"SELECT [...]" part of my CREATE TABLE statement works properly.

Sub test()

Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection

cmd.CommandText = "CREATE TABLE tbl1 (uid INTEGER PRIMARY KEY, foo
INTEGER)"
cmd.Execute , , adCmdText

cmd.CommandText = "INSERT INTO tbl1 (uid, foo) VALUES (1, 2)"
cmd.Execute , , adCmdText

cmd.CommandText = "CREATE TABLE tbl2 (uid INTEGER PRIMARY KEY, bar
INTEGER)"
cmd.Execute , , adCmdText

cmd.CommandText = "INSERT INTO tbl2 (uid, bar) VALUES (1, 3)"
cmd.Execute , , adCmdText

cmd.CommandText = "CREATE TABLE tbl3 AS (SELECT tbl1.[uid], tbl1.
[foo], tbl2.[bar] FROM tbl1 INNER JOIN tbl2 ON tbl1.[uid] = tbl2.
[uid])"
cmd.Execute , , adCmdText

End Sub

Jun 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Dr Duck | last post by:
GDay all, Something seems odd to me.... I wrote a simple C# function public void bind(ref object a, ref object b, bool atob) { if(atob) b = a; else
2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
1
by: Ueslei R. Valentini | last post by:
Hi! Does anyone figured out this error when trying to create a new page in a web project under Windows2003, using Visual Studio .Net 2003? "Automation server can't create object " HSH Ueslei
5
by: Matt S. | last post by:
I have been using C# 2005 Express to make class libraries for use in another software program. Each version of this software has a different .NET API, so maintaining multiple solutions of the same...
1
by: Emie | last post by:
Dear All, I would be most grateful if some one could please help me. My database was working fine untill yesterday but suddenly today when I try to click on a Find button or Search button OR even...
5
by: vipinkrajput | last post by:
Hi, i m using javascript for writing in a file,the code is correctly working with IE 6.0, i m getting the error like "Automation server can't create object" in IE 7.0 while using...
0
by: dim505 | last post by:
hi friends, I'm new to this forum. I have created and build a dll but at first it was getting the error"Automation server can't create object" after a lot of head ache,I got the script...
0
by: syedsarfaraz | last post by:
Hi There! Could anybody please help regarding the below issue. We had a COM+ component deployed on Windows 2000/NT machine it was working fine, I mean when it was being invoked from other...
3
by: Keith G Hicks | last post by:
I created a dll for com (in vb.net 2005) so that I could access it's functions from an ms access app. I created the tlb file successfully. On my dev machine I referenced it in my access app and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.