Share via


ListFields Collection

SharePoint Designer Developer Reference

Represents a collection of ListField objects that define the text fields used within lists.

Remarks

The ListField object is a base class that defines the common members used by the different types of fields in Office SharePoint Designer. For example, the ListFieldCurrency and ListFieldNumber objects allow you to customize the way in which currency and numeric information is displayed.

Use Fields(Index), where Index is either the name of the list or its position within the collection, to return a single ListField object. The following example displays the names of all fields in the first list of the active Web site. If the Web site contains no lists, a message is displayed to the user.

Use the Add method to add a new ListField object to the ListFields collection.

Visual Basic for Applications
Sub ListFields()
'Display the names of fields in the current list
    Dim objApp As Application
    Dim objField As ListField
    Dim strType As String
    Set objApp = Application
    If Not ActiveWeb.Lists Is Nothing Then
        For Each objField In objApp.ActiveWeb.Lists.Item(0).Fields
            If strType = "" Then
                'Create new string
                strType = objField.Name & vbCr
            Else
                'Add next field name to string
                strType = strType & objField.Name & vbCr
            End If
        Next objField
        MsgBox "The names of the fields in this list are: " & _
                vbCr & strType
    Else
        'Otherwise display message to user
        MsgBox "The current web contains no lists."
    End If
End Sub

See Also