How Can I Know How Many Full Records Have Been Selected? (1 Viewer)

whdyck

Registered User.
Local time
Today, 08:51
Joined
Aug 8, 2011
Messages
169
In a form's VBA code, I'd like to know whether a full record has been selected, like when the user selects one or more rows before deleting with the Del key.

Is this possible?

According to http://msdn.microsoft.com/en-us/library/office/ff823187.aspx, Me.SelHeight returns the number of rows that have been selected within the selection rectangle. If I select a rectangle of cells in Datasheet view, for example, Me.SelHeight will be > 0 even though full records have not been selected. I want to know how many full records have been selected. Is this possible?

Thanks for any help you can give.

Wayne
 

Rx_

Nothing In Moderation
Local time
Today, 07:51
Joined
Oct 22, 2009
Messages
2,803
Everything I looked at indicates it is part of the Form object. Since it is not part of any rerecordset object, there probably is not a way.
My guess is that it looks at the recordcount for the form object.

So, maybe you could write something like a hot key or a toggle button that would toggle the records in the list box to only show the Full records while using the me.selheight?
 

whdyck

Registered User.
Local time
Today, 08:51
Joined
Aug 8, 2011
Messages
169
After playing with this a bit, I think this works:

Code:
If Me.SelHeight > 0 And Me.SelWidth = GetColumnCount Then
   ...
End If
 
Private Function GetColumnCount() As Integer
On Error GoTo GetColumnCountErr
 
    ' Declarations & Setup
    Static sintColumnCount As Integer
    Dim ctl As Control
 
    ' Main Line
    If sintColumnCount = 0 Then
 
        For Each ctl In Me.Controls
            If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acListBox Or ctl.ControlType = acCheckBox Then
                sintColumnCount = sintColumnCount + 1
            End If
        Next ctl
 
    End If
 
    GetColumnCount = sintColumnCount
 
GetColumnCountBye:
    Exit Function
 
GetColumnCountErr:
    ...
    Resume GetColumnCountBye
End Function

Seems to work for Form view or Datasheet view, with visible or invisible columns (which is surprising).

Or am I missing something?

Thanks.

Wayne
 

Users who are viewing this thread

Top Bottom