Public Function Select10()
Dim RSUsers, RSLocations
Dim varBookmark
Dim TotalLocations As Long
Dim SelectedLocation As Long
Dim i As Integer
Set RSUsers = CurrentDb.OpenRecordset("Select ID, First, Last from tblUsers where Observer = true")
Set RSLocations = CurrentDb.OpenRecordset("Select Location from tblLocations")
RSLocations.MoveLast
TotalLocations = RSLocations.RecordCount
While Not RSUsers.EOF
For i = 1 To 10
Randomize
SelectedLocation = CLng((TotalLocations * Rnd) + 1)
RSLocations.MoveFirst
varBookmark = RSLocations.Bookmark
RSLocations.Move SelectedLocation
'Here you can also write in a table or do whatever you want. I just printed in the debug window.
Debug.Print RSUsers!First, RSUsers!Last, "Location - ", RSLocations!Location
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Next i
RSUsers.MoveNext
Wend
End Function
Dim sZoneNumber(9) As String
Dim r(10) As String
Dim s As String
Dim i As Integer
Dim x As Integer
s = "123456789"
i = 0
Do While Len(s) > 0
x = CStr(Int(Rnd(10) * 10))
If InStr(1, s, x) Then
i = i + 1
r(i) = x
s = Replace(s, x, "")
Debug.Print r(i)
End If
Loop
sZoneNumber1 = r(1)
sZoneNumber2 = r(2)
sZoneNumber3 = r(3)
sZoneNumber4 = r(4)
sZoneNumber5 = r(5)
sZoneNumber6 = r(6)
sZoneNumber7 = r(7)
sZoneNumber8 = r(8)
sZoneNumber9 = r(9)
Public Function Select10()
Dim RSUsers, RSLocations
Dim varBookmark
Dim TotalLocations As Long
Dim SelectedLocation As Long
Dim i As Integer
Dim j As Integer
Set RSUsers = CurrentDb.OpenRecordset("Select ID, First, Last from tblUsers where Observer = true")
While Not RSUsers.EOF
For j = 1 To 9
Set RSLocations = CurrentDb.OpenRecordset("Select Location from tblLocations where zone='Zone" & j & "'")
RSLocations.MoveLast
TotalLocations = RSLocations.RecordCount
For i = 1 To 10
Randomize
SelectedLocation = CLng(((TotalLocations - 1) * Rnd) + 1)
RSLocations.MoveFirst
varBookmark = RSLocations.Bookmark
RSLocations.Move SelectedLocation - 1
'Here you can also write in a table or do whatever you want. I just printed in the debug window.
Debug.Print RSUsers!First; RSUsers!Last, "Zone - "; j, "Location - "; RSLocations!Location
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Next i
Next j
RSUsers.MoveNext
Wend
End Function
Public Function Select10()
Dim RSUsers, RSLocations
Dim varBookmark
Dim TotalLocations As Long
Dim SelectedLocation As Long
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim UsedZones(9) As Variant
Set RSUsers = CurrentDb.OpenRecordset("Select ID, First, Last from tblUsers where Observer = true")
j = 1
While Not RSUsers.EOF
Do
Randomize
k = CLng((9 * Rnd) + 1)
Loop While InStr(1, vbNullChar & Join(UsedZones, vbNullChar) & vbNullChar, vbNullChar & k & vbNullChar) > 0
UsedZones(j) = k
j = j + 1
Set RSLocations = CurrentDb.OpenRecordset("Select Location from tblLocations where zone='Zone" & k & "'")
RSLocations.MoveLast
TotalLocations = RSLocations.RecordCount
For i = 1 To 10
Randomize
SelectedLocation = CLng(((TotalLocations - 1) * Rnd) + 1)
RSLocations.MoveFirst
varBookmark = RSLocations.Bookmark
RSLocations.Move SelectedLocation - 1
'Here you can also write in a table or do whatever you want. I just printed in the debug window.
Debug.Print RSUsers!First; RSUsers!Last, "Zone - "; k, "Location - "; RSLocations!Location
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Next i
RSUsers.MoveNext
Wend
End Function
Regards