这是从《Access数据库系统开发从基础到实践》一书中的示例--考试管理系统中的一段代码:
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
为什么运行时总弹出对话框提示:
运行时错误‘13’
类型不匹配
无法正常运行下去。主要问题出红色部分代码。
有谁可以解决这一问题--
[此贴子已经被作者于2007-1-1 12:14:39编辑过]
|