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