CurrentView Property

Applies To

Form.

Description

You can use the CurrentView property to determine how a form is currently displayed. For example, you might need to know whether a form is in Form view or Datasheet view before you attempt to place controls on the form using Visual Basic.

Settings

The CurrentView property uses the following settings.

Setting Description
0 The form is displayed in Design view.
1 The form is displayed in Form view.
2 The form is displayed in Datasheet view.


This property is available only in a macro or Visual Basic and is read-only in all views.

Remarks

You can also use this property to perform different tasks depending on the view. For example, a menu command running code can determine which view the form is displayed in and perform one task if the form is displayed in Form view or another task if it’s displayed in Datasheet view.

See Also

DefaultView, ViewsAllowed Properties.

Example

The following example determines whether a form is in Form or Datasheet view. If it’s in Form view, a message is displayed in a text box on the form; if it’s in Datasheet view, the same message is displayed in a message box.


Function GetCurrentView(frm As Form, strDisplayMsg As String)
    Const conFormView = 1
    Const conDataSheet = 2
    Dim intView As Integer
    intView = frm.CurrentView
    Select Case intView
        Case conFormView
            frm!MessageTextBox.SetFocus        ' Set focus to text box.
            ' Display message in text box.
            frm!MessageTextBox = strDisplayMsg
        Case conDataSheet
            ' Display message in message box.
            MsgBox strDisplayMsg    
    End SelectFunction