Selected records on form

  • Thread starter Thread starter Terry
  • Start date Start date
T

Terry

I have a form displaying n rows of data. I want to select
a group of records (Select row the Shift Click another
row) and then work with the selected records, say, rows
2,3,4,5,6 from 20 rows

In a list box this is easy. Are there any properties which
would allow me to pull, say, an ID from each of the
selected rows so I can build a SQL WHERE clause?
 
SelTop and SelHeight give you the first row in a selection, and the number
of rows selected.

Setting the form's RecordSelectors property to Yes makes it easy to select
multiple contiguous rows at once.
 
Hello Allen
Yes, SelTop moves the top selected row to the top of the
display. What I want to do, however, is to get a field
value from each of the selected rows. What criteria can I
use in a loop to move through the selected
records/recordsetclone to interogate each record and know
when I have reached the last selected record???
Thanks
Terry
 
Reading SelTop gives you the absolute position of the top-most selected
record:

Sub TestForm()
Dim frm As Form
Dim rs As DAO.Recordset
Dim lngI As Long

Set frm = Forms("SomeForm")
Set rs = frm.RecordsetClone

rs.AbsolutePosition = frm.SelTop - 1
For lngI = 0 To frm.SelHeight - 1
Debug.Print rs![SomeField]
rs.MoveNext
Next

Set rs = Nothing
Set frm = Nothing
End Sub
 
SelHeight and SelTop apply while the records have focus,
hence SELtop and SELheight. If you click a button to, say,
scan the records selected, generate a sql clause and then
open a report, the selected records lose focus and the
reported SelHeight when the button is clicked is zero.

I will use this & generate & store a sql clause every time
the form is clicked but I feel there has to be a better
way.
Thanks for your assistance
-----Original Message-----
Reading SelTop gives you the absolute position of the top- most selected
record:

Sub TestForm()
Dim frm As Form
Dim rs As DAO.Recordset
Dim lngI As Long

Set frm = Forms("SomeForm")
Set rs = frm.RecordsetClone

rs.AbsolutePosition = frm.SelTop - 1
For lngI = 0 To frm.SelHeight - 1
Debug.Print rs![SomeField]
rs.MoveNext
Next

Set rs = Nothing
Set frm = Nothing
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hello Allen
Yes, SelTop moves the top selected row to the top of the
display. What I want to do, however, is to get a field
value from each of the selected rows. What criteria can I
use in a loop to move through the selected
records/recordsetclone to interogate each record and know
when I have reached the last selected record???
Thanks
Terry makes
it easy to select


.
 
Yes, the records are no longer selected when you click a button on the form.

A button on a toolbar might work?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Terry said:
SelHeight and SelTop apply while the records have focus,
hence SELtop and SELheight. If you click a button to, say,
scan the records selected, generate a sql clause and then
open a report, the selected records lose focus and the
reported SelHeight when the button is clicked is zero.

I will use this & generate & store a sql clause every time
the form is clicked but I feel there has to be a better
way.
Thanks for your assistance
-----Original Message-----
Reading SelTop gives you the absolute position of the top- most selected
record:

Sub TestForm()
Dim frm As Form
Dim rs As DAO.Recordset
Dim lngI As Long

Set frm = Forms("SomeForm")
Set rs = frm.RecordsetClone

rs.AbsolutePosition = frm.SelTop - 1
For lngI = 0 To frm.SelHeight - 1
Debug.Print rs![SomeField]
rs.MoveNext
Next

Set rs = Nothing
Set frm = Nothing
End Sub
 
Thanks Allen
I do have it working but it is a little messy. I have
declared form variables and in the form on_click event of
the subform I check the top and height set those into the
variables. When the button is clicked the selection is
lost but can be retrieved from the form level variables. I
use these to do the processing and then restore the
selection.
Thanks for you continued support
Terry
-----Original Message-----
Yes, the records are no longer selected when you click a button on the form.

A button on a toolbar might work?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

SelHeight and SelTop apply while the records have focus,
hence SELtop and SELheight. If you click a button to, say,
scan the records selected, generate a sql clause and then
open a report, the selected records lose focus and the
reported SelHeight when the button is clicked is zero.

I will use this & generate & store a sql clause every time
the form is clicked but I feel there has to be a better
way.
Thanks for your assistance
-----Original Message-----
Reading SelTop gives you the absolute position of the
top-
most selected
record:

Sub TestForm()
Dim frm As Form
Dim rs As DAO.Recordset
Dim lngI As Long

Set frm = Forms("SomeForm")
Set rs = frm.RecordsetClone

rs.AbsolutePosition = frm.SelTop - 1
For lngI = 0 To frm.SelHeight - 1
Debug.Print rs![SomeField]
rs.MoveNext
Next

Set rs = Nothing
Set frm = Nothing
End Sub


.
 
Back
Top