Required Property

Microsoft FrontPage Visual Basic

Required Property

Returns or sets a Boolean that determines if the field is required. If the field is required, it cannot be removed from the current list. Read/write.

expression.Required

expression    Required. An expression that returns one of the objects in the Applies To list.

Example

The following example displays the names and default values of all required fields in the current list. If no required fields exist or if the active Web site contains no lists, a message is displayed to the user.

    Sub DisplayRequiredFields()
'Displays the names and default values
'of all required fields in the first list of
'the web.

    Dim objApp As FrontPage.Application
    Dim objField As ListField
    Dim objFields As ListFields
    Dim strReq As String
    Dim BlnFound As Boolean

    Set objApp = FrontPage.Application
    Set objFields = objApp.ActiveWeb.Lists.Item(0).Fields
    'set found flag to false
    BlnFound = False
    If Not ActiveWeb.Lists Is Nothing Then
        For Each objField In objFields
             'If field is required, add to list
            If objField.Required = True Then
                If strReq = "" Then
                    'if first value in string
                    strReq = objField.Name & "  -  " & _
                    objField.DefaultValue & vbCr
                    'The list contains at least 1 required field
                    BlnFound = True
                Else
                    'add value to string
                    strReq = strReq & objField.Name & "  -  " & _
                    objField.DefaultValue & vbCr
                End If
            End If
        Next objField

    Else
        'display message to user
        MsgBox "The active web contains no lists."
    End If
    If BlnFound = True Then
        MsgBox "The current list contains the following required fields: " & _
               vbCr & strReq
    Else
        MsgBox "The current list contains no required field(s)."
    End If
End Sub