HWAterBern
New member
- Local time
- Tomorrow, 01:25
- Joined
- Nov 17, 2010
- Messages
- 1
I am trying to generate a random sample of a population, no repeats, and can run the code in Excel with user inputs, however I am trying to run in Access and can't get my head around the code. I welcome any input...
The code will run the randomization, I just can't populate the table with the numbers. I also need to limit the new table to the pop variable population.
My sample population can be 17 from 25 or 125 from 8600...
PLEASE HELP!!!
Code:
Sub Random()
[INDENT]Dim dbs As Database
Set dbs = CurrentDb
dbs.Execute "CREATE TABLE TestSample " _
& "(Ident CHAR);"
[/INDENT][INDENT]Small = Forms![Revised Test Sample Size]![ID Min]
big = Forms![Revised Test Sample Size]![ID Max]
pop = Forms![Revised Test Sample Size]![Sample Size]
Dim i As Long
Dim randomIndex As Long
For i = Small To big
Randomize
randomIndex = Int(Rnd() * big) + 1
While randomIndex < Small: randomIndex = Int(Rnd() * big) + 1: Wend
dbs.Execute " INSERT INTO TestSample " _
& "(Ident) VALUES " _
& "(randomIndex.value);"
Next i
' Code from Excel
' Range(InputBox("Enter first Cell")).Resize(pop, 1) = Application.Transpose(myArray)
dbs.Close
[/INDENT]End Sub
My sample population can be 17 from 25 or 125 from 8600...
PLEASE HELP!!!
Last edited: