sps said:
I have a form a single "main" record is displayed and a
list of other records on a subform. Multiple subform
records will match to the one main record. I need to be
able to have the user select multiple records on the
subform so I can set this match. As of now I can only
select records that are next to each other.
You cannot do this with a subform, if you try to do it by clicking,
shift-clicking, or ctrl-clicking on record selector. You can either use
a multiselect list box for the purpose, or you can add a Yes/No field
"IsSelected" to the table on which the subform is based, bind a check
box on the subform to that field, and check off the ones you want to
select. You'd probably want a command button to clear all the check
boxes, or else clear them all in the main form's Current event.
All this is assuming that the subform is always supposed to show all
records, and not just those that you've related to the main form's
record. This is not the usual way to relate tables. Is it your
intention to store the relationship between the selected subform records
and the main form record? If so, you'll need three tables: the main
form's table, the table that contains the records from which to choose,
and a table that will contain one record for each match-up between the
other two tables (this table's fields are the keys from each of the
other tables). In such a case, the most common way to present it is
with a subform based on that third, linking table. Then each new record
is created by either selecting the second table's key from a combo box
on the subform, or sometimes by choosing the matching record from a list
box on the main form, which action runs code that creates the record for
the subform.
I also need to be able to calculate a total of a field in
the selected records and compare it with a value on the
main form. How would I reference the selected records or
get a count of how many records are selected?
That depends on how you've set it up, and whether the relating records
are actually stored in a third table or are merely transitory. If you
explain a bit about what you're trying to do and why, this part should
be pretty simple.