On the subform to set the record set
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Click()
- CurrentSelectionTop = Me.SelTop
- CurrentSelectionHeight = Me.SelHeight
- End Sub
On the main form to total the selected records and return the sum to a msgbox(error handling commented out for dev purposes):
Expand|Select|Wrap|Line Numbers
- Private Sub btnRecordSum_Click()
- 'On Error GoTo Err_btnRecordSum_Click
- Dim curTotal As Currency
- Dim lngFirstRec As Long
- Dim lngNRecs As Long
- With Me![SutaList].Form
- 'Forms![frmMaster]![frmCar]
- lngFirstRec = CurrentSelectionTop
- lngNRecs = CurrentSelectionHeight
- If lngNRecs > 0 Then
- With .RecordsetClone
- .AbsolutePosition = lngFirstRec - 1
- While lngNRecs > 0
- curTotal = curTotal + Nz(!Amount, 0)
- lngNRecs = lngNRecs - 1
- If lngNRecs > 0 Then
- .MoveNext
- End If
- Wend
- End With
- End If
- End With
- 'Exit_btnRecordSum_Click:
- ' Exit Sub
- 'Err_btnRecordSum_Click:
- ' MsgBox Err.Description
- ' Resume Exit_btnRecordSum_Click
- MsgBox "The total is " & curTotal
- End Sub
My problem is that when I click the btnRecordSum, the selected rows become unselected, and the msgbox returns an amount of 0 which is correct for no selection. Am I missing something obvious here? How do I retain the selection after the subform loses focus?