CreateField

  • Thread starter Thread starter David Kennedy
  • Start date Start date
D

David Kennedy

Can anyone tell me how to create a field (using code) in an already existing
table?

Thanks in advance
David K
 
This example creates a field named TestField in an existing table, Table1:
Dim db As DAO.Database
Dim tdf As DAO.TableDef

Set db = CurrentDb()
Set tdf = db.TableDefs("Table1")
tdf.Fields.Append tdf.CreateField("TestField", dbText, 80)

If you prefer, you can do it by executing a query statement:
Dim db As DAO.Database
Dim strSql As String

Set db = CurrentDb()
strSql = "ALTER TABLE Table1 ADD COLUMN TestField TEXT (80);"
db.Execute strSql, dbFailOnError
 
Back
Top