Solved

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

Posted on 2012-03-09
9
365 Views
Last Modified: 2012-03-11
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.
0
Comment
Question by:lthames
9 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 37703481
Are these databases going to be used separately with each user having their own data?
0
 
LVL 57
ID: 37703516
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.
0
 

Author Comment

by:lthames
ID: 37703810
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.
0
 
LVL 42

Expert Comment

by:dqmq
ID: 37703930
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.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 166 total points
ID: 37704805
I'm not sure I understand why you want to go to all this trouble, rather than just distributing a blank database?

Do you intend to just send them an mde of accde file?

If you are not going to use any sort of install program, and you are using Access 2007/2010, then you might want to consider adding a table to your application front-end and storing the blank database as an attachment in that table.

Then during the first run of the application, your code could check to see whether the database exists on the users system and if not, extract the blank database from that table.  This would save you A LOT of effort.

I don't use attachments much, but this is the way I deploy occasionally deploy images and templates for various Word or Excel files that go with my Access applications.
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 167 total points
ID: 37704957
<<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.>>

 Not like your thinking no.    Just use TransferDatabase method then or possibly even more simply, do a file copy of a "master template" DB you provide and rename it when you copy it.  Then you have a complete DB ready for them quick and easy.

And since you'd never touch the master copy, you can always create more.

Jim.
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 167 total points
ID: 37706143
fyed mentioned distributing a blank db. Personally I think that is the best approach, one with the least number of headaches, very low maintenance as you just need to update your install with the new table, not the scripts itself. The ready made db has everything you need for the setup. Any lookup tables will exist with data already defined etc (if you have such a thing). If your tables change often you can copy the db then create scripts to truncate the tables (or use what Jim said).

Other option is for you to maintain sql scripts that create tables, setup indexes etc. This you run on your installs. Maintenance is higher here though.
If you do not have them you can use a tool like dbwscript to generate your initial scripts and then maintain them or use the sample code that is here. These should be treated as something to get you started with creating the scripts, not the tool to do everything for you.
Remember once the initial scripts have been done, you have to remember to modify them as and when new tables are created or existing tables are modified.
0
 
LVL 57
ID: 37706988
@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.
0
 

Author Closing Comment

by:lthames
ID: 37707509
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!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now