Private Sub cmdSelect_Click()
Dim SQL As String
Dim sWhere As String
Dim iCount As Integer
Dim i As Integer
Dim j As Integer
Dim iSelectHowMany As Integer
Dim aSel() As Integer
Dim IsRepeated As Boolean
Dim vItem As Variant
iSelectHowMany = 3
SQL = "Select * from [tblORDERS]"
' Find number of records in table.
iCount = DCount("*", "tblORDERS")
Randomize
i = Int(iCount * Rnd()) + 1
ReDim aSel(0)
aSel(0) = i
j = 1
Do While j < iSelectHowMany
IsRepeated = False
Do While Not IsRepeated
i = Int(iCount * Rnd()) + 1
For Each vItem In aSel
If vItem = i Then
IsRepeated = True
Exit For
End If
Next vItem
If Not IsRepeated Then
ReDim Preserve aSel(j)
aSel(j) = i
j = j + 1
Exit Do
End If
Loop
Loop
For Each vItem In aSel
sWhere = sWhere & ", " & vItem
Next
SQL = SQL & " where [OrderID] in (" & Mid(sWhere, 2) & ")"
Me.subform.Form.RecordSource = SQL
End Sub