下面的选题代码:
Private Sub 自动选择试题_Click()
Dim intRnd As Integer
Dim i, j As Long
Dim IsPrint As Boolean
Set cn = CurrentProject.Connection
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE 试题 SET 试题.是否打印 = " & False & ""
sql1 = "select * from 试题选择"
rs1.Open sql1, cn, 3, 2, 1
rs1.MoveFirst
For i = 1 To rs1.RecordCount
sql2 = "select * from 试题 where 试题类型1=" & rs1.Fields("试题类型1") & " and 试题类型2=" & rs1.Fields("试题类型2") & ""
rs2.Open sql2, cn, 3, 2, 1
IntArray = rs2.RecordCount
Randomize Timer
If rs2.RecordCount > 0 Then
For j = 1 To rs1.Fields("题数")
rs2.MoveFirst
intRnd = Int((IntArray - 1) * Rnd(j) + 1)
rs2.Move intRnd
Do While True
If Not rs2.EOF Then
IsPrint = rs2.Fields("是否打印")
Else
IsPrint = True
End If
If IsPrint = False Then
rs2.Fields("是否打印") = True
rs2.Update
Exit Do
Else
If rs2.EOF Then
rs2.MoveFirst
Else
rs2.MoveNext
End If
End If
Loop
Next
rs2.Close
End If
rs1.MoveNext
Next
rs1.Close
Set cn = Nothing
DoCmd.SetWarnings True
MsgBox "选择完毕!", vbInformation, Me.Caption
End Sub