Creating a Database

See AlsovbhowCreateDatabaseSee                 ExamplevbhowCreateDatabaseEx>Low

A database file can contain a number of objects, and some of those objects can contain other objects or collections of objects.  Before you create a database3GGA17, you should have a good idea about what information will be stored in your database and what kinds of tables3N276AP, fields, and indexes6SGX4U you'll need to store and track that information.

Data Manager

The easiest way to create or modify the structure of your database is to use Microsoft Access or the Data Manager, which you can open by choosing the Data Manager command on the Window menu.

Professional Edition

If you have the Professional Edition, you can write code to create and modify the structure of a database.  After you have planned the structure of your tables, the basic steps to create a database are:

  1. Dim a variable for the Database object you want to create.

  2. Use CreateDatabase to create an empty database, and Set to assign it to your Database object variable.

  3. Create new TableDef objects for each table and add them to the TableDefs collection of the Database with the Append method.  Creating a table involves the following steps:

  a. Create new TableDef objects.  For each one, set the Name property to the name you want for the table.

  b. Create new Field objects for each table.  For each Field, set the following properties:
Size (optional)
Attributes (optional)

  c. Add each Field to the Fields collection of a TableDef with the Append method.  Repeat steps ac for each Field in a TableDef.

  d. Create one or more new Index objects for each table.  For each Index, set the following properties:
Primary (optional, and for only one Index per table)
Unique (optional)

  e. Add each Index object to the Indexes collection of the TableDef with the Append method.  A table can have none or several indexes.

   f. Add the TableDef object to the Database with the Append method.  This is the step that actually creates the object in the database file.