Size, Type Properties Example (MDB)
The following example creates a new Field object and sets its Size and Type properties. The procedure then appends the new object to the Fields collection of the Employees table in the TableDefs collection of the database.
Sub NewField()
Dim dbs As Database, tdf As TableDef
Dim fld As Field
' Return reference to current database.
Set dbs = CurrentDb
' Return reference to Employees table.
Set tdf = dbs.TableDefs!Employees
' Create Field object.
Set fld = tdf.CreateField("DaysOfVacation")
' Set field properties.
fld.Type = dbText
fld.Size = 20
' Append fld to Fields collection.
tdf.Fields.Append fld
Set dbs = Nothing
End Sub
You can also use the CreateField method to set the Name, Type, and Size properties if you provide name, type, and size as arguments.
Set fld = tdfEmployees.CreateField("DaysOfVacation", dbText, 20)