>
Required Property
Applies To
Field Object, Index Object.
Description
Sets or returns a value that indicates whether a Field object requires a non-Null value or whether all the fields in an Index object must be filled in. For an object not yet appended to a collection, this property is read/write. For an Index object, this property setting is read-only for objects appended to Indexes collections in Recordset and TableDef objects.
Settings and Return Values
The setting or return value is a Boolean expression indicating whether an object requires a non-Null value. True indicates that a Null value is not allowed.
Remarks
For a Field object, use of the Required property depends on its parent object, as shown in the following table.
Parent Object | Usage |
|
Index | Not supported |
QueryDef | Read-only |
Recordset | Read-only |
Relation | Not supported |
TableDef | Read/write |
For a Field object, you can use the Required property along with the AllowZeroLength, ValidateOnSet, or ValidationRule property to determine the validity of the Value property setting for that Field object. If the Required property is set to False (0), the field can contain Null values as well as values that meet the conditions specified by the AllowZeroLength and ValidationRule property settings.
Tip
When you can set this property for either an Index object or a Field object, set it for the Field object. The validity of the property setting for a Field object is checked before that of an Index object.
See Also
AllowZeroLength Property, QueryDef Object, Required Property, ValidateOnSet Property, ValidationRule Property, ValidationText Property, Value Property.
Example (Microsoft Access)
The following example creates a new Index object on an Employees table and sets the Required property for the index. The new index consists of two fields, LastName and FirstName.
Sub NewIndex()
Dim dbs As Database, tdf As TableDef, idx As Index
Dim fldLastName As Field, fldFirstName As Field, rst As Recordset
' Return Database variable that points to current database.
Set dbs = CurrentDb
Set tdf = dbs.TableDefs!Employees
' Return Index object that points to new index.
Set idx = tdf.CreateIndex("FullName")
' Create and append index fields.
Set fldLastName = idx.CreateField("LastName", dbText)
Set fldFirstName = idx.CreateField("FirstName", dbText)
idx.Fields.Append fldLastName
idx.Fields.Append fldFirstName
' Ensure value is entered for each field in the index.
idx.Required = True
' Append Index object.
tdf.Indexes.Append idx
End Sub