|
新建一个模块,把这段代码贴上,按下F5键运行试试看。- 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
- rst1.Open " SELECT * FROM 学生 ORDER BY 学生.分数 DESC", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- rst2.Open "考场考号", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- rst3.Open "考场", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
- For i = 1 To rst3.RecordCount
- For j = 1 To rst3(3).Value
- On Error Resume Next
- rst2.AddNew
- rst2(0) = rst1(1)
- rst2(1) = rst1(2)
- rst2(2) = rst3(1)
- rst2(3) = Format(j, "00")
- rst2.Update
- rst1.MoveNext
- Next j
- rst3.MoveNext
- Next i
- rst1.Close
- rst2.Close
- rst3.Close
- End Sub
复制代码 之前曾做过一个随机安排考场的实例,比这个复杂一些,如有兴趣,可以店家下面链接(附件需要注册才能下载)查看:
http://www.access-cn.com/thread-98298-1-1.html |
|