CustomViewsOnly Property

Microsoft Outlook Visual Basic

CustomViewsOnly Property

       

Returns or sets a Boolean that determines which views are displayed on the Views menu for a given folder. If set to the True, only user created-views will appear on the menu. Read/write.

expression.CustomViewsOnly

expression   Required. An expression that returns a MAPIFolder object.

Example

The following example prompts the user to select a view option. If the user chooses to view all views, the CustomViewsOnly property is set to False. If the user chooses to view only custom views, the CustomViewsOnly property is set to True. Once the property is changed, the outcome of the change is displayed for the user.

Sub SetCusView()
'Sets the CustomViewsOnly property depending on the user's response

    Dim olApp As Outlook.Application
    Dim nmsName As NameSpace
    Dim fldFolder As MAPIFolder
    Dim lngAns As Long

    Set olApp = Outlook.Application
    Set nmsName = olApp.GetNamespace("MAPI")
    Set fldFolder = nmsName.GetDefaultFolder(olFolderInbox)

    'Prompt user for input
    lngAns = MsgBox("Would you like to view only custom views in the view menu?", vbYesNo)

    Call SetVal(fldFolder, lngAns)

End Sub

Sub SetVal(ByRef fldFolder As MAPIFolder, ByVal lngAns As Long)
'Modifies the CustomViewsOnly property to display views on the Views menu

    If lngAns = vbYes Then
        fldFolder.CustomViewsOnly = True
    Else
        fldFolder.CustomViewsOnly = False
    End If

    'Display only custom views
    If lngAns = vbYes Then
       MsgBox "The " & fldFolder.Name & " folder will now display only custom views."
    'display all views
    Else
       MsgBox "The " & fldFolder.Name & " folder will now display all views."
    End If

End Sub