|
'执行代码前先引用Microsoft ActiveX Data Object 2.8 Library
- Sub test()
- Dim rst1 As New ADODB.Recordset
- Dim rst2 As New ADODB.Recordset
- Dim rst3 As New ADODB.Recordset
- Dim i As Long, j As Long, k As Long
- Dim Arr
- rst1.Open "select distinct 班级 from 测试数据", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- Do Until rst1.EOF
- rst2.Open "select 姓名 from 测试数据 where 班级='" & rst1(0) & "'", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- rst3.Open "结果表", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- Arr = rst2.GetRows()
- For i = 0 To UBound(Arr, 2)
- For j = i + 1 To UBound(Arr, 2)
- For k = j + 1 To UBound(Arr, 2)
- rst3.AddNew
- rst3(0) = Arr(0, i)
- rst3(1) = Arr(0, j)
- rst3(2) = Arr(0, k)
- rst3(3) = rst1(0)
- Next
- Next
- Next
- rst3.UpdateBatch
- rst3.Close
- rst2.Close
- rst1.MoveNext
- Loop
- rst1.Close
- End Sub
复制代码
附上2007版本附件,如果你的是2003的话,请新建一个模块,把上述代码贴上,在VBE界面下,按下F5执行即可。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|