473,382 Members | 1,349 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,382 software developers and data experts.

Create an empty table that has the structure of another table - in VBA

Hi

I need to create a table that is empty, but has the data structure (i.e. the same columns) of another table. Both tables should be in the same DB.

I need this as part of my VBA code.

I searched the web and found this:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("CREATE TABLE test_table AS SELECT * FROM test_table WHERE 1=2")
  2.  
It's not working.. The query itself doesn't even work in the query browser. Of course it doesn't work in VBA either. I get a message: "syntax error in create table statement".

What am I doing wrong?
Or else - is there a different solution direction to this?
Note that I need a solution in VBA for ms access, not for the query browser.

Many thanks
Rachel
Nov 23 '10 #1
3 15042
TheSmileyCoder
2,322 Expert Mod 2GB
This should work:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as string
  2. strSQL="SELECT * INTO [New table name goes here]" & _
  3.        " FROM [Original Table Name goes here]" & _
  4.        " WHERE 1=2;"
  5. docmd.SetWarnings false
  6.   DoCmd.RunSql strSQL
  7. docmd.setwarnings True
Nov 23 '10 #2
Thank you, this works!!
From what I understand access will accept "select into" commands but not "create" commands.
Need to keep this in mind.
If anyone knows why this is, I'd love to know..
Nov 23 '10 #3
NeoPa
32,556 Expert Mod 16PB
It's quite simple really Rachel. The SELECT INTO SQL string is in the correct format, whereas the CREATE TABLE SQL string isn't. Also, the CREATE TABLE SQL command is not a Make Table command. It creates the table structure only, with no facility for adding in any data.
Nov 23 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Deja User | last post by:
This is probably very simple but I can't figure out a way to update one table from another table. Here is an example: ------ TABLEA ------ first_name last_name
1
by: Mike9900 | last post by:
What is the best way to copy DataRow from one table to another table, without copying its structure, which means copying only its data. -- Mike
1
by: thengfen | last post by:
Hi! Im having a problem in transfering a set of records from a table to another table. The scenario is when i select combo box (Course taken such as diploma in IT), then the process will...
1
by: satishkhachane | last post by:
-------------------------------------------------------------------------------- I want to select one or more columns from one typed datatable and add it to another table . how I can do this ? ...
1
by: lcourchesne | last post by:
Hi there, This is what I am trying to do: Create a query that will insert a column from Table 2 into Table 1. These two tables are exactly the same in structure, however, there is no unique...
1
by: Sakakini | last post by:
How can I append last entry from one table to another table???
4
by: xoozlez | last post by:
Hi there, How do I insert new records from a dbo table to another table? This is what I have: 1 dbo_company 1 Member (table) I made a query in dbo_company with the criteria I only want to...
2
by: tomash | last post by:
Hi! I ve got two tables in Access 2007. I want to update a field of DataTable from another table, DataSumTable when two of their fields equals. ( the fields : Name and Period) I tried this...
3
by: anil2083 | last post by:
How to migrate the comma separated values from one table to another table? suppose we have table i.e XYZ and we have comma separated values in few columns i.e( column_name and values are...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.