Create new field with validation rule : TableDefs « Access « VBA / Excel / Access / Word






Create new field with validation rule

 
Sub exaCreateTable()
    Dim db As Database
    Dim tblNew As TableDef
    Dim fld As Field
     
    Set db = CurrentDb
     
    Set tblNew = db.CreateTableDef("MyTable")
    Set fld = tblNew.CreateField("MyField", dbText, 100)
    fld.AllowZeroLength = True
    fld.DefaultValue = "Unknown"
    fld.Required = True
    fld.ValidationRule = "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

1.Database relations
2.Reference column name from TableDefs
3.Add new property to TableDef
4.List table properties
5.Create a relation
6.Create an index