Private Sub Command4_Click()
Dim i As Long, cnt As Long, n As Long
Dim rst As DAO.Recordset
Const SelNumbers As Long = 5
Set rst = sfm学生表.Form.Recordset.Clone
cnt = rst.RecordCount
Randomize
For i = 1 To SelNumbers
n = cnt - (Int(cnt * Rnd) + rst.AbsolutePosition)
Debug.Print n
If n <> 0 Then
rst.Move n
End If
Debug.Print "随机记录ID"; rst.Fields(0).Value
Next
问题1用到的
'--------------------------------------------------
'Purpose: 检查指定的值是否在列表中
'Input:
' [in] FindVal: 需要查找的值
'Output: (Boolean)
'--------------------------------------------------
Public Function IsInList(ArrayList() As Long, ByVal FindVal As Long) As Boolean
Dim i As Long
For i = LBound(ArrayList) To (UBound(ArrayList))
If ArrayList(i) = FindVal Then IsInList = Not IsInList: Exit Function
Next i
End Function
Private Sub Command4_Click()
Me.学生表_子窗体.Form.RecordSource = "Select TOP 5 * From 学生表 where 年龄=" & Me.Text2.Value & " Order BY Rnd(Len(姓名))"
Me.学生表_子窗体.Form.Requery
End Sub