Link to home
Start Free TrialLog in
Avatar of Lynn Thames
Lynn ThamesFlag for United States of America

asked on

Can I use an existing table in Access to create code to build an identical table

Greetings!

I have an application that uses an access database with several large tables.  I want to write a program that will dynamically build the database for new users instead of having to provide them with a copy of a blank database.

I prefer not to have to manually type up the code to create each of the tables with the correct field names, type, and sizes.  I figure that I could load the table and go through the fields collection and append each field to a build a create table command.

But is there an automated way that would do this for me from an existing table structure.
Avatar of Norie
Norie

Are these databases going to be used separately with each user having their own data?
Simple way:  take a look at the TransferDatabase method, which allows you to copy objects from one DB to another.

Keep a empty table in a "master" DB and then use that to create your new DB.

If the tables are dynamic, then either you can go the DAO route as you described (add a tabledef, fields, indexes, etc) or you can use SQL DML (Data Manipulation Language) statements such as CREATE table

Describe a bit more what it is your doing  and we'll get you started.

Jim.
Avatar of Lynn Thames

ASKER

imnorte:   This is to set up a new database for someone who buys the the application.  Right now we have to provide a empty database but I would really like for the install to create the database and then build the tables.  Or at least start with an empty database and have the install build the tables.

Jim,  What I actually want to do is have the file built dynamically.  I know how to create the tables from my programming language with the create command. . . . . and I know I can write a program to go through all of the table defs to get what I need to build the tables.   I was just hoping there was a shortcut that would take existing tables and actually create the "CREATE TABLE . . . . " command to use.
Supporting Jim....TransferDatabase is the method of choice.  

Probably, I would make an Access application to create the new db, then do a series of import/export steps. In that application, use TransferDatabase to import the tables you want.  You can use the Structure-Only option so you don't need to maintain an empty table.  The use TransferDatabase to export the table to the New database.  

You can use the same approach for forms, queries, reports and other database objects.
SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@rocki,

  Really nice to see you popup...it's been too long!

  Drop me a line at jimdettman"at"earthlink.net.  Would love to hear what you think about the new site.

Jim.
Although none offered the approach I was looking for, each offered insight into a better solution than I was wanting to implement anyway.

Thanks to all of you for your input!