The information in this article applies to:
SUMMARYThere is no command in Microsoft Access to programmatically create a table. This article demonstrates a method and a user-defined Access Basic function you can use to accomplish this task. The user-defined function requires a "template table" that you can create. MORE INFORMATION
Create the template table before you create the user-defined function. The
template table is used to define the data types that will be used in the
new table.
This template can be used as a generic template for using the CreateTable procedure. Once you have defined your data types in a template table, you can use the CreateTable procedure in the following manner: DefinitionCreateTable <target table>, <template table>, <structure definition>Where: <target table> is the name of the table to create and MUST NOT exist in the database. You may want to code a routine to check for the existence of such a table before invoking this procedure. Where: <structure definition> = "<field name> As <user-defined data type>,..." NOTE: There are quotation marks around the entire <structure definition> parameter. Below is an example of how you would invoke the CreateTable procedure to create a table based on the template table discussed earlier:
How CreateTable WorksAs mentioned earlier, there is no Access Basic command or function to create a table. Fortunately, Microsoft Access supports the SQL SELECT INTO command that can be used to create a table. However, SELECT INTO requires a table for its FROM clause, which explains why you need to have a template table.CreateTable parses the structure definition, then builds a SELECT INTO statement based on that definition. Once the SQL statement is built, the QueryDef object is employed to invoke the command, resulting in a new table. Procedure ListingNOTE: In the following sample code, an underscore (_) is used as a line continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.
Keywords : kbusage TblModfy |
Last Reviewed: March 10, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |