Here's an example of creating a table with one field:
'**************************************************
Sub exaCreateTable()
'DAO DDL example
'demonstrates creating a table, fields, properties
Dim db As DAO.Database
Dim tblNew As DAO.TableDef
Dim fld As DAO.Field
' Create the table and a field
Set db = CurrentDb
Set tblNew = db.CreateTableDef("NewTable")
Set fld = tblNew.CreateField("NewField", dbText, 100)
' Set field properties
fld.AllowZeroLength = True
fld.DefaultValue = "Unknown"
fld.Required = True
fld.ValidationRule = "Like 'A*' or Like 'Unknown'"
fld.ValidationText = "Known value must begin with A"
' Append field to Fields collection
tblNew.Fields.Append fld
' Append table to TableDef collection
db.TableDefs.Append tblNew
End Sub
'**************************************************
Appending the Fields to the Tabledef and the Tabledef to the Tabledefs
Collection are key here.
For more examples, download this file:
http://www.rogersaccesslibrary.com/download3.asp?SampleName=DAO.mdb
And check out the "Chapter 11" and "Chapter 13" modules.
--
--Roger Carlson
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L