Which records selected in a Continuous Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I determine the selected records when I click on the record selector
and select multiple records.

I know I can use the forms SelTop property to determine the FIRST row but
what about the others? For example I want to be able to select say 10
important transactions and add up the amounts.

Thanks
Tom
 
SelHeight gives the number of records.

You could FindFirst the first selected record, and then loop through the
number of selected records in the form's RecordsetClone. That should work
regardless of how the form is filtered or sorted.
 
Ah... SelHeight! Many thanks.

But FindFirst needs a value for the criteria yet I do not know the contents
of the FIRST selected record.
 
This kind of thing should do it:


Function SumSelectedRows(frm As Form, strField As String) As Currency
'Purpose: Sum the selected records in a continous form/datasheet.
'Arguments: frm = a reference to the form.
' strField = name of the field to sum.
'Return: Summed value as currency.
'Example: To sum the Amount field on the current form:
' MyTotal = GetSum(Me, "Amount")
Dim rs As DAO.Recordset
Dim lng As Long
Dim curTotal As Currency

Set rs = frm.RecordsetClone
If rs.RecordCount > 0 Then
rs.MoveFirst
rs.Move frm.SelTop - 1
Do While lng < frm.SelHeight And Not rs.EOF
curTotal = curTotal + Nz(rs(strField), 0)
rs.MoveNext
lng = lng + 1
Loop
End If

SumSelectedRows = curTotal
Set rs = Nothing
End Function
 
Allen,

Instead of summing records, I tried to adapt your code to parse a series of
selected text records to an external app, but it didn't work.

I have this working code below that will take a 'fixed' set of records, but
I want to be able to select just some of the records, but instead of adding
the numbers, want to parse the data elsewhere. I tried to adjust your code,
but couldn't reconcile your use of recordsetclone with my code's use of
OpenRecordset


this is my working code:

Private Sub btn_Run_Test_Show_Map_Click()
'Assume lngRunNo is either declared elsewhere or passed as an argument
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sRoute As String
Dim iWPCount As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("Select [Run_waypoint], [Postcode] from
tbl_Run_Reveal_Target where [Run_No]=" & Me.Run_No & " and [Postcode]<> 'X'
order by [OrderSeq];", dbOpenForwardOnly)

Do Until rs.EOF
iWPCount = iWPCount + 1
sRoute = sRoute & IIf(iWPCount = 1, "from: ", " to: ") &
rs![Run_waypoint] & ", " & "London, " & rs![Postcode]
rs.MoveNext
Loop
rs.Close

If iWPCount >= 2 Then

Parent.Form.Run_Test_WebBrowser.Navigate
"http://maps.google.co.uk/maps?f=q&hl=en&q=" & sRoute

Else
MsgBox "Run must have at least two waypoints"
End If
End Sub


Below is what I tried, but it threw an error: Object doesn't support this
property or method. on this line:

Do While lng < Forms![frm_Runs]![frm_Run_Reveal_Selector].SelHeight And Not
rs.EOF



Private Sub btn_map_selected_records_Click()
'Purpose: Sum the selected records in a continous form/datasheet.
'Arguments: frm = a reference to the form.
' strField = name of the field to sum.
'Return: Summed value as currency.
'Example: To sum the Amount field on the current form:
' MyTotal = GetSum(Me, "Amount")
Dim rs As DAO.Recordset
Dim lng As Long
Dim curTotal As Currency

Set rs = Forms![frm_Runs]![frm_Run_Reveal_Selector].Form.RecordsetClone
' Set rs = db.OpenRecordset("Select [Run_waypoint], [Postcode] from
tbl_Run_Reveal_Target where [Run_No]=" & Me.Run_No & " and [Postcode]<> 'X'
order by [OrderSeq];", dbOpenForwardOnly)

If rs.RecordCount > 0 Then
rs.MoveFirst
rs.Move Forms![frm_Runs]![frm_Run_Reveal_Selector].Form.SelTop - 1
Do While lng < Forms![frm_Runs]![frm_Run_Reveal_Selector].SelHeight
And Not rs.EOF
lng = lng + 1

rs.MoveNext
Loop
End If

sRoute = sRoute & IIf(lng = 1, "from: ", " to: ") & rs![Run_waypoint] &
", " & "London, " & rs![Postcode]


If lng >= 2 Then

Parent.Form.Run_Test_WebBrowser.Navigate
"http://maps.google.co.uk/maps?f=q&hl=en&q=" & sRoute

Else
MsgBox "Run must have at least two waypoints"
End If

End Sub
 
Back
Top