SelHeight, SelWidth Properties

Applies To   Form, QueryDef object, Table, TableDef object.

Description

You can use the SelHeight property to specify or determine the number of selected rows (records) in the current selection rectangle in a table, query, or form datasheet, or the number of selected records in a continuous form. You can use the SelWidth property to specify or determine the number of selected columns (fields) in the current selection rectangle. For example, if you've selected a group of rows and columns within Datasheet view of the Customers table, you can use the SelHeight and SelWidth properties to determine the number of rows and columns in the selection rectangle.

Setting

These properties aren't available in Design view. These properties are only available by using a macro or Visual Basic.

Remarks

If there's no selection, the value returned by these properties will be zero. Setting either of these properties to 0 removes the selection from the datasheet or form.

If you've selected one or more records in the datasheet (using the record selectors), you can't change the setting of the SelWidth property (except to set it to 0). If you've selected one or more columns (using the column headings), you can't change the setting of the SelHeight property (except to set it to 0).

You can use these properties with the SelTop and SelLeft properties to specify or determine the actual position of the selection rectangle on the datasheet. If there's no selection, then the SelTop and SelLeft properties return the row number and column number of the cell with the focus.

The SelHeight and SelWidth properties contain the position of the lower-right corner of the selection rectangle. The SelTop and SelLeft property values determine the upper-left corner of the selection rectangle.

See Also   SelTop, SelLeft properties.

Example

The following example shows how to use the SelHeight, SelWidth, SelTop, and SelLeft properties to determine the position and size of a selection rectangle in datasheet view. The SetHeightWidth procedure assigns the height and width of the current selection rectangle to the variables lngNumRows, lngNumColumns, lngTopRow, and lngLeftColumn, and displays those values in a message box.

Sub SetHeightWidth(frm As Form)
    Dim lngNumRows As Long, lngNumColumns As Long
    Dim lngTopRow As Long, lngLeftColumn As Long
    Dim strMsg As String

    If frm.CurrentView = 2 Then        ' Form is in Datasheet view.
        lngNumRows = frm.SelHeight        ' Number of rows selected.
        lngNumColumns = frm.SelWidth        ' Number of columns selected.
        lngTopRow = frm.SelTop            ' Topmost row selected.
        lngLeftColumn = frm.SelLeft        ' Leftmost column selected.
        strMsg = "Number of rows: " & lngNumRows & vbCrLf
        strMsg = strMsg & "Number of columns: " & lngNumColumns & vbCrLf
        strMsg = strMsg & "Top row: " & lngTopRow & vbCrLf
        strMsg = strMsg & "Left column: " & lngLeftColumn
        MsgBox strMsg
    End If
End Sub