P
Paul Hitchcock
I have a subform in datasheet view and the users want to be able to
select multiple cells in a column and display the sum value of the
selected cells, similar to selecting multiple cells in Excel?
I've managed to accomplish this, but it only works if they are looking
at the data unfiltered and in the same record order as the form's
recordset.
Is there another way to do this so that it still works even if they
have a filter on or they have sorted by another column?
Below is the code for the MouseUp event of the BoxCount control that
they are trying to view the sum of:
Private Sub BoxCount_MouseUp(Button As Integer, Shift As Integer, x As
Single, y As Single)
On Error GoTo ErrTrap
If Me.SelHeight > 1 And Me.SelWidth = 1 Then
If Me.SelLeft = Me.BoxCount.ColumnOrder + 1 Then
'User has selected multiple rows in the BoxCount column
Dim r As Integer
Dim SumBoxCount As Integer
Dim rst As New ADODB.Recordset
Set rst = Me.RecordsetClone
rst.AbsolutePosition = Me.SelTop
For r = 1 To Me.SelHeight
SumBoxCount = SumBoxCount + Nz(rst!BoxCount, 0)
rst.MoveNext
Next r
rst.Close
Set rst = Nothing
MsgBox "Sum: " & SumBoxCount, , "Box Count"
End If
End If
ExitSub:
Exit Sub
ErrTrap:
ShowError Me.Name, "BoxCount_MouseUp"
Resume ExitSub
End Sub
select multiple cells in a column and display the sum value of the
selected cells, similar to selecting multiple cells in Excel?
I've managed to accomplish this, but it only works if they are looking
at the data unfiltered and in the same record order as the form's
recordset.
Is there another way to do this so that it still works even if they
have a filter on or they have sorted by another column?
Below is the code for the MouseUp event of the BoxCount control that
they are trying to view the sum of:
Private Sub BoxCount_MouseUp(Button As Integer, Shift As Integer, x As
Single, y As Single)
On Error GoTo ErrTrap
If Me.SelHeight > 1 And Me.SelWidth = 1 Then
If Me.SelLeft = Me.BoxCount.ColumnOrder + 1 Then
'User has selected multiple rows in the BoxCount column
Dim r As Integer
Dim SumBoxCount As Integer
Dim rst As New ADODB.Recordset
Set rst = Me.RecordsetClone
rst.AbsolutePosition = Me.SelTop
For r = 1 To Me.SelHeight
SumBoxCount = SumBoxCount + Nz(rst!BoxCount, 0)
rst.MoveNext
Next r
rst.Close
Set rst = Nothing
MsgBox "Sum: " & SumBoxCount, , "Box Count"
End If
End If
ExitSub:
Exit Sub
ErrTrap:
ShowError Me.Name, "BoxCount_MouseUp"
Resume ExitSub
End Sub