Hi folks,
I have a ten thousand record table with (among others) Location, Sub-Location, Item and autonumbered fields. I need to select varying numbers of property items for about fifty of the Location / Sub-Locations. For example, if Tucson is the Location and Nogales is the Sub-Location, I need to randomly select 25 out of 100 of their items and create a report from that. Each Location / Sub-Location will have a different amount of property items, and therefore a differing amount of items that will need to be selected. The number of items to be selected is arbitrarily picked by the client, so we have to input it by hand.
Here is what I have thought of so far. I could divide the total number of items at a Loc/SubLoc by the number of items needed to be selected. This would yield, for lack of a better word, a selection index. I could then compare the line number divided by the selection index and compare it with the integer of that same calculation. Therefore, if the line number is evenly divisible by the selection index, it gets selected for the table. In the end, I should (in theory) come up with the table I need. So for Tucson/Nogales, the selection index would be four, and I would get records numbered 4, 8, 12, etc. for a total of 25 records. This works great, but I run short when I need to select sixty out of the hundred records.
The other way I could do it would be to randomly select a record, count all records selected so far and if the number is larger than the number I need, I stop, if less than the number I go back and select another. Sounds great in theory, but I have no idea what to do. I could write a nice program on my Commodore 64 to do that, but I don’t know where to begin with MS Access. Is there a feature that will let me select a random number of records? It does seem that I can choose a random number, and tie it to the line number. But if the Sub-Loc starts at line number 2,843 and ends at 2,967, how well would that work?
Could anyone please point me in the right (random) direction?
Thank you very, very much.
Rhythmdvl
PS In case you are wondering how I got myself into this mess, reread the story about the tailor and the giant. The one about the tailor who kills seven flies in one swoop…