Required 属性


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


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
                    'add value to string
                    strReq = strReq & objField.Name & "  -  " & _
                    objField.DefaultValue & vbCr
                End If
            End If
        Next objField

        '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
        MsgBox "The current list contains no required field(s)."
    End If
End Sub