Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access97 - Create Table Via Code 1

Status
Not open for further replies.

SHardy

Programmer
May 9, 2001
231
GB
Would someone be able to give me basic instruction on how to create a new table in an Access97 database via VBA? I need to create a table with the required fields, and to be able to set the field properties (data type/format, indexes, etc).

Thanks.
 
Hi,
You should use SQL instructions in a VBA function.

Sub CreateTable1()
Dim dbs As Database
Set dbs = OpenDatabase(".mdb")
' Create a table with two text fields.
dbs.Execute "CREATE TABLE ThisTable " _
& "(FirstName CHAR, LastName CHAR, " _
dbs.Close
End Sub

Have a look in access help, look for CREATE TABLE.

Regards.

Fcail
 
So simple it should've been obvious. Only one other question on this then. When defining the data types, the text descriptions differ to those used by Access.

Example:
When using the CREATE TABLE method defining a field as "INTEGER", the field is created as a "Long Integer" rather than an "Integer".

Where can a find a list of data type definitions for SQL?
 
Access SQL
------------
integer integer ( long integer)
integer SMALLINT ( short integer )
text varchar(NN)
date date

For more informations, look in microsoft jet help, you can access it by the SQL mode.

Fcail
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top