Create a table with validation rule
Sub exaCreateTable()
Dim db As Database
Dim tblNew As TableDef
Dim fld As Field
Set db = CurrentDb
Set tblNew = db.CreateTableDef("NewTable")
Set fld = tblNew.CreateField("NewField", dbText, 100)
fld.AllowZeroLength = True
fld.DefaultValue = "Unknown"
fld.Required = True
fld.ValidationRule = "Instr$(Like 'A*' or Like 'Unknown'"
fld.ValidationText = "Known value must begin with A"
tblNew.Fields.Append fld
db.TableDefs.Append tblNew
End Sub
Related examples in the same category