跪求高手帮我解决!!毕业论文的题目,急啊!!
我编写的试题库在点“保存试题”时,出现运行时间错误‘91’:对象变量或with块变量未设置
光标指向‘添加新记录 下面的 objRs!题干 = txtContent
下面是我的程序,谢谢高手帮下!!(最好能把错误的地方帮我改正)
Dim objRs As ADODB.Recordset
Dim isAdding As Boolean
Private Sub Form_Load()
Set objRs = New ADODB.Recordset
'设置记录开放锁定,在执行Update方法时锁定记录
objRs.LockType = adLockOptimistic
objRs.CursorType = adOpenDynamic '使用动态集游标
objRs.CursorLocation = adUseClient '使用客户端游标
objRs.Open "判断题", CurrentProject.Connection '打开记录集,获取数据
cboChapter.SetFocus
cboChapter.ListIndex = 0 '设置默认章节
objRs.Filter = "章节=1" '用默认章节筛选数据
'显示第一条记录
Show_Data
End Sub
Private Sub Show_Data()
If objRs.RecordCount > 0 Then
'显示当前记录数据
If Not objRs.EOF And Not objRs.BOF Then
txtContent = objRs!题干
frmAnswer.Value = objRs!答案 + 1
frmLevel.Value = objRs!难度
txtNews = "记录:" & objRs.AbsolutePosition & "/" & objRs.RecordCount
End If
Else
txtContent = ""
txtNews = "本章无试题记录!"
End If
End Sub
Private Sub cmdFirst_Click()
If objRs.AbsolutePosition > 1 Then
objRs.MoveFirst
Show_Data
End If
End Sub
Private Sub cmdPrevious_Click()
If Not objRs.BOF Then
objRs.MovePrevious
Show_Data
End If
End Sub
Private Sub cmdNext_Click()
If Not objRs.EOF Then
objRs.MoveNext
Show_Data
End If
End Sub
Private Sub cmdLast_Click()
If objRs.RecordCount > objRs.AbsolutePosition Then
objRs.MoveLast
Show_Data
End If
End Sub
Private Sub cmdEdit_Click()
txtContent.Locked = False
frmAnswer.Locked = False
frmLevel.Locked = False
cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
End Sub
Private Sub cmdDelete_Click()
If objRs.RecordCount <= 0 Then Exit Sub
n = MsgBox("确认删除当前试题吗?", vbQuestion + vbYesNo)
If n = vbYes Then
objRs.Delete adAffectCurrent
objRs.Update
objRs.MoveNext
If objRs.EOF And objRs.RecordCount > 0 Then objRs.MoveLast
Show_Data
End If
End Sub
Private Sub cmdAdd_Click()
txtNews = "添加新记录......"
txtContent = ""
txtContent.Locked = False
frmAnswer.Locked = False
frmLevel.Locked = False
cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
isAdding = True
End Sub
Private Sub cmdSave_Click()
If isAdding Then
If txtContent = "" Then
If MsgBox("新增试题题干不能为空,取消添加记录吗?", vbYesNo) = vbYes Then
Show_Data '显示当前记录
Else
txtContent.SetFocus '返回窗体
Exit Sub
End If
Else
'添加新记录
objRs.AddNew
objRs!题干 = txtContent
objRs!章节 = cboChapter.Value
objRs!答案 = frmAnswer.Value - 1
objRs!难度 = frmLevel.Value
objRs.Update
MsgBox "成功保存数据!"
End If
Else
If txtContent = "" Then
MsgBox "题干不能为空!"
txtContent.SetFocus
Exit Sub
Else
objRs!题干 = txtContent
objRs!章节 = cboChapter.Value
objRs!答案 = frmAnswer.Value - 1
objRs!难度 = frmLevel.Value
objRs.Update
MsgBox "成功保存数据!"
End If
End If
Show_Data
txtContent.Locked = True
frmAnswer.Locked = True
frmLevel.Locked = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
cmdFirst.Enabled = True
isAdding = False
End Sub
Private Sub cmdExit_Click()
DoCmd.Close '关闭窗体
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objRs = Nothing
End Sub