I have an access database that uses a subform to display records, one column of which is charge data (currency). My users need to verify the charges against the paper form they are scanned from, so I would like to allow them to select a subset of these charges (shift click) and sum them into a message box to verify page by page that the records are correct, or find incorrect records. I found the following vba code and added it to the db
On the subform to set the record set
On the main form to total the selected records and return the sum to a msgbox(error handling commented out for dev purposes):
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?
On the subform to set the record set
Code:
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):
Code:
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?
Comment