D David Kennedy Nov 23, 2004 #1 Can anyone tell me how to create a field (using code) in an already existing table? Thanks in advance David K
Can anyone tell me how to create a field (using code) in an already existing table? Thanks in advance David K
A Allen Browne Nov 23, 2004 #2 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
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
A Allen Browne Nov 23, 2004 #3 Should have also pointed you to a list of the names to use for the different field types at: http://members.iinet.net.au/~allenbrowne/ser-49.html For the first approach, use the DAO column. For the 2nd, use the DDL column.
Should have also pointed you to a list of the names to use for the different field types at: http://members.iinet.net.au/~allenbrowne/ser-49.html For the first approach, use the DAO column. For the 2nd, use the DDL column.