| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 774 人关注过本帖
标题:跪求高手帮我解决!!毕业论文的题目,急啊!!
只看楼主 加入收藏
frankboy05
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-4-30
收藏
 问题点数:0 回复次数:7 
跪求高手帮我解决!!毕业论文的题目,急啊!!
我编写的试题库在点“保存试题”时,出现
运行时间错误‘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
搜索更多相关主题的帖子: 毕业论文 
2008-04-30 22:14
wangtuan7788
Rank: 1
等 级:新手上路
帖 子:286
专家分:0
注 册:2007-10-8
收藏
得分:0 
好像是   objRs!题干 = txtContent
要写成 objRs.fields("题干") = txtContent
这么写行的话,以下的类似句子也都这样

你笑我和你们不一样,我笑你们大家都一样~
2008-05-01 00:05
hxfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:5810
专家分:118
注 册:2005-4-7
收藏
得分:0 
把objRS锁类型改成adOpenDynamic这样测试行不行

2008-05-01 00:30
frankboy05
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-4-30
收藏
得分:0 
我把大家的建议都试了下,还是错误,现在还出现了
运行时错误'3021' BOF或EOF中有一个是“真”,或者当前记录已被删除
还是指向objRs!题干=txtContent
郁闷啊!!
2008-05-01 09:26
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
在addnew之前 objRs.open "select * from 表名 where 1=2",Conn,3,2
2008-05-01 10:16
frankboy05
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-4-30
收藏
得分:0 
急求高手!!帮我解决
谢谢大家!判断题已经解决!现在是单选题的问题,在点‘保存试题’时候
出现  运行时错误‘424’:要求对象,光标指向bjRs!答案 = chkAnswerA.Value & chkAnswerB.Value & chkAnswerC.Value & chkAnswerD.Value
还有例如chkAnswerA之类的要写入控件吗,因为我的选择控件按纽名称要填
optAnswerA,就没位置写chkAnswerA了


下面是我的程序,希望大家继续帮我下




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!题干
              txtAnswerA = objRs!选项1
              txtAnswerB = objRs!选项2
              txtAnswerC = objRs!选项3
              txtAnswerD = objRs!选项4
              chkAnswerA = -1 * Val(Mid(objRs!答案, 1, 1))
              chkAnswerB = -1 * Val(Mid(objRs!答案, 2, 1))
              chkAnswerC = -1 * Val(Mid(objRs!答案, 3, 1))
              chkAnswerD = -1 * Val(Mid(objRs!答案, 4, 1))
              frmLevel.Value = objRs!难度
              txtNews = "记录: " & objRs.AbsolutePosition & "/" & objRs.RecordCount
           End If
      Else
           txtContent = ""
                                  txtContent = ""
           txtAnswerA = ""
           txtAnswerB = ""
           txtAnswerC = ""
           txtAnswerD = ""
           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
     txtAnswerA.Locked = False
     txtAnswerB.Locked = False
     txtAnswerC.Locked = False
     txtAnswerD.Locked = False
     optAnswerA.Locked = False
     optAnswerB.Locked = False
     optAnswerC.Locked = False
     optAnswerD.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 = ""
     txtAnswerA = ""
     txtAnswerB = ""
     txtAnswerC = ""
     txtAnswerD = ""
     chkAnswerA = 0
     chkAnswerB = 0
     chkAnswerC = 0
     chkAnswerD = 0
     txtContent.Locked = False
     txtAnswerA.Locked = False
     txtAnswerB.Locked = False
     txtAnswerC.Locked = False
     txtAnswerD.Locked = False
     optAnswerA.Locked = False
     optAnswerB.Locked = False
     optAnswerC.Locked = False
     optAnswerD.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!选项1 = txtAnswerA
          objRs!选项2 = txtAnswerB
          objRs!选项3 = txtAnswerC
          objRs!选项4 = txtAnswerD
          objRs!答案 = chkAnswerA.Value & chkAnswerB.Value & chkAnswerC.Value & chkAnswerD.Value
          objRs!难度 = frmLevel.Value
          objRs.Update
          MsgBox "成功保存数据!"
      End If
   Else
      If txtContent = "" Then
           MsgBox "题干不能为空!"
           txtContent.SetFocus   '返回窗体
           Exit Sub
       Else
          objRs!题干 = txtContent
          objRs!章节 = cboChapter.Value
          objRs!选项1 = txtAnswerA
          objRs!选项2 = txtAnswerB
          objRs!选项3 = txtAnswerC
          objRs!选项4 = txtAnswerD
          objRs!答案 = Abs(chkAnswerA.Value) & Abs(chkAnswerB.Value) & Abs(chkAnswerC.Value) & Abs(chkAnswerD.Value)
          objRs!难度 = frmLevel.Value
          objRs.Update
          MsgBox "成功保存数据!"
        End If
     End If
     Show_Data
     txtContent.Locked = True
     txtAnswerA.Locked = True
     txtAnswerB.Locked = True
     txtAnswerC.Locked = True
     txtAnswerD.Locked = True
     optAnswerA.Locked = True
     optAnswerB.Locked = True
     optAnswerC.Locked = True
     optAnswerD.Locked = True
     frmLevel.Locked = True
     cmdPrevious.Enabled = True
     cmdNext.Enabled = True
     cmdLast.Enabled = True
     cmdFirst.Enabled = True
     isAdding = False
End Sub

Private Sub cmdExit_Clcik()
      DoCmd.Close   '关闭窗体
End Sub

Private Sub Form_Unload(Cancel As Integer)
      Set objRs = Nothing
End Sub
2008-05-01 20:41
快速回复:跪求高手帮我解决!!毕业论文的题目,急啊!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020688 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved