Required 属性

       

返回或设置 Boolean 类型的值,该值确定域是否必选。如果域必选,则不能从当前列表将其删除。可读写。

expression.Required

expression  必选。返回“应用于”列表中的对象之一的表达式。

示例

下列示例显示当前列表中所有必选域的名称和默认值。如果不存在必选域,或者活动站点不包含列表,则向用户显示一条消息。

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