Quote:
Originally Posted by artemetis
Thanks folks!!! The more I looked at what I was trying to do (and as I lay in bed staring at the ceiling)...I realized I'd have to go the "RST" route.....
I love this website...always great people to help out!
NeoPa - I have the same peeve..... :o)
The following Algorithm will Print the Random UIDs of either 7 or 8 Males (15 total Males and Females) from tblSuffolk. To generate Random Females, and to parallel the functionality in the other Table, is easy from this point on. I basically threw this together and I must admit it is a tad too much,
before NeoPa states so! (LOL), but it is nonetheless a viable solution. There is definately room for improvement, and it does not check against the possibility of generating the same Record Position more than once. It did work on test data, to my surprise (LOL)!
-
-
Dim intNumOfMales As Integer
-
Dim intNumOfFemales As Integer
-
Dim intNumOfRecs As Integer
-
Dim intCounter As Integer
-
Dim intRandomPosition As Integer
-
Dim strSQL As String
-
Dim MyDB As DAO.Database
-
Dim rstEmployees As DAO.Recordset
-
Randomize
-
'Need 7 or 8 Males and 7 or 8 Females
-
If Rnd() < 0.5 Then
-
intNumOfMales = 7
-
Else
-
intNumOfMales = 8
-
End If
-
intNumOfFemales = 15 - intNumOfMales
-
'Do the Males first, forget the Females for now
-
strSQL = "Select * From tblSuffolk Where [empGender] = 'M';"
-
Set MyDB = CurrentDb
-
Set rstEmployees = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
-
With rstEmployees
-
.MoveLast
-
.MoveFirst
-
intNumOfRecs = .RecordCount 'Number of Males in tblSuffolk
-
'Pick intNumOfMales Random Record Positions, move to that Record,
-
'then Print the result
-
For intCounter = 1 To intNumOfMales
-
intRandomPosition = Int(Rnd * intNumOfRecs) + 1
-
If intRandomPosition = 1 Then
-
Debug.Print rstEmployees![empUID]
-
Else
-
.Move intRandomPosition - 1
-
Debug.Print rstEmployees![empUID]
-
End If
-
rstEmployees.MoveFirst
-
Next
-
End With
-
-
rstEmployees.Close
-
Set rstEmployees = Nothing
-