Share via


Field2.Required Property

Access Developer Reference

Sets or returns a value that indicates whether a Field2 object requires a non-Null value.

Syntax

expression.Required

expression   A variable that represents a Field2 object.

Remarks

For a Field2 not yet appended to the Fields collection, this property is read/write.

The availability of the Required property depends on the object that contains the Fields collection, as shown in the following table.

If the Fields collection belongs to a Then Required is

Index object

Not supported

QueryDef object

Read-only

Recordset object

Read-only

Relation object

Not supported

TableDef object

Read/write

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 Field2 object. If the Required property is set to False, the field can contain null values as well as values that meet the conditions specified by the AllowZeroLength and ValidationRule property settings.

Bb257459.vs_note(en-us,office.12).gif  Note
When you can set this property for either an Index object or a Field2 object, set it for the Field2 object. The validity of the property setting for a Field2 object is checked before that of an Index object.

Example

This example uses the Required property to report which fields in three different tables must contain data in order for a new record to be added. The RequiredOutput procedure is required for this procedure to run.

Visual Basic for Applications
  Sub RequiredX()

Dim dbsNorthwind As Database Dim tdfloop As TableDef

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

With dbsNorthwind ' Show which fields are required in the Fields ' collections of three different TableDef objects. RequiredOutput .TableDefs("Categories") RequiredOutput .TableDefs("Customers") RequiredOutput .TableDefs("Employees") .Close End With

End Sub

Sub RequiredOutput(tdfTemp As TableDef)

Dim fldLoop As Field2

' Enumerate Fields collection of the specified TableDef ' and show the Required property. Debug.Print "Fields in " & tdfTemp.Name & ":" For Each fldLoop In tdfTemp.Fields Debug.Print , fldLoop.Name & ", Required = " & _ fldLoop.Required Next fldLoop

End Sub