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编辑过]
作者: tz-chf 时间: 2007-1-1 04:52
& ""
没什么用作者: fan0217 时间: 2007-1-3 00:20
sql2 = "select * from 试题 where 试题类型1=" & rs1.Fields("试题类型1") & " and 试题类型2=" & rs1.Fields("试题类型2") & ""
试题类型1和试题类型2是什么类型的字段?如果是文本,请使用以下代码.
sql2 = "select * from 试题 where 试题类型1='" & rs1.Fields("试题类型1") & "' and 试题类型2='" & rs1.Fields("试题类型2") & "'"作者: yongjiu3 时间: 2007-1-8 01:15
试题类型1和试题类型2是数字类型的字段。
Option Compare Database
Option Explicit
Dim cn As Connection
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim IntArray As Integer
Dim sql1 As String
Dim sql2 As String