程序删除功能一掉删除最后一条记录的时候,删除操作执行成功,但会出现错误提示:实时错误'3021':BOF或EOF中有一个是"真",或者当前记录已被删除,所需的操作要求一个当前的记录.实现删除功能的代码:Private Sub CmdDelete_Click()       '删除毕业生信息
    If Adodc1.Recordset.RecordCount > 0 Then
   a = MsgBox("您确实要删除这条数据吗?", vbYesNo)
   If a = vbYes Then
      '删除当前记录
      Adodc1.Recordset.Delete
      Adodc1.Recordset.Update
      If Adodc1.Recordset.EOF = False Then
         Adodc1.Recordset.MoveNext
      Else
         Adodc1.Recordset.MoveFirst
      End If
      Call view_data     '调用显示student表中数据的过程
      '设置按钮有效或无效
      CmdSave.Enabled = False
      CmdEsc.Enabled = False
      CmdAdd.Enabled = True
      CmdModify.Enabled = True
      For i = 0 To 3
          CmdMD(i).Enabled = True
      Next i
   End If
  End If
End SubPrivate Sub view_data()     '声明一个显示student表中数据的过程
    With Adodc1.Recordset
        '将student表中各字段的值赋给对应的控件
       If .Fields("姓名") <> "" Then Text1.text = .Fields("姓名")
        If .Fields("性别") <> "" Then Combo1.text = .Fields("性别")
        If .Fields("毕业年") <> "" Then Text2.text = .Fields("毕业年")
        If .Fields("学校名称") <> "" Then Combo2.text = .Fields("学校名称")
        If .Fields("日期") <> "" Then Text3.text = .Fields("日期")
        If .Fields("专业名称") <> "" Then Combo3.text = .Fields("专业名称")
        If .Fields("修业年限") <> "" Then Text4.text = .Fields("修业年限")
        If .Fields("档案材料") <> "" Then Text5.text = .Fields("档案材料")
        If .Fields("单位名称") <> "" Then Combo4.text = .Fields("单位名称")
        If .Fields("培养方式") <> "" Then Combo5.text = .Fields("培养方式")
        If .Fields("报到地址") <> "" Then Text6.text = .Fields("报到地址")
        If .Fields("开始日期") <> "" Then DTPicker1.Value = .Fields("开始日期")
        If .Fields("结束日期") <> "" Then DTPicker2.Value = .Fields("结束日期")
        If .Fields("文件编号") <> "" Then Text13.text = .Fields("文件编号")
        If .Fields("备注") <> "" Then Text14.text = .Fields("备注")
     End With
End Sub在上面代码中view_data()部分的If .Fields("姓名") <> "" 是出错后编译器指向的代码行,我在CmdDelete_Click()部分已经用
      If Adodc1.Recordset.EOF = False Then
         Adodc1.Recordset.MoveNext
      Else
         Adodc1.Recordset.MoveFirst
      End If
      Call view_data     
代码对出现的这个错误预先做了避免,为什么还会出现这样的错误提示????????

解决方案 »

  1.   

    If Adodc1.Recordset.EOF = False Then
             Adodc1.Recordset.MoveNext
          Else
             Adodc1.Recordset.MoveFirst
          End If
          Call view_data 
    --------------------------------------------
    改为:
          If Adodc1.Recordset.EOF = False Then
             Adodc1.Recordset.MoveNext
             Call view_data
          Else
             Adodc1.Recordset.MoveFirst
          End If
      

  2.   

    或者在view_data() 过程里加上一句判断:Private Sub view_data()     '声明一个显示student表中数据的过程
        With Adodc1.Recordset
           If .EOF Then Exit Sub  '<-------------------------加这句
            '将student表中各字段的值赋给对应的控件
           If .Fields("姓名") <> "" Then Text1.text = .Fields("姓名")
            If .Fields("性别") <> "" Then Combo1.text = .Fields("性别")
          ......
      

  3.   

    在CmdDelete_Click()部分已经用
          If Adodc1.Recordset.EOF = False Then
             Adodc1.Recordset.MoveNext
          Else
             Adodc1.Recordset.MoveFirst
          End If
          Call view_data     
    代码对出现的这个错误预先做了避免,为什么还会出现这样的错误提示????????
    ----------------------------------------------------------------------------------
    看看view_data的 代码,如果 Adodc1.Recordset.EOF 为真,那么在执行到 .Fields("姓名") 时就会发生错误
    而上面CmdDelete_Click()的代码,不管都调用 view_data过程,而在view_data过程里又没有进行判断,所以,当EOF为真时,肯定会发生错误
      

  4.   

    不好意思,漏了几个字而上面CmdDelete_Click()的代码,不管Adodc1.Recordset.EOF 是否为真,都调用 view_data过程,而在view_data过程里又没有进行判断,所以,当EOF为真时,肯定会发生错误
      

  5.   

    If not isnull(.Fields("专业名称")) Then Text1.text = .Fields("姓名")
      很多情况是null存在出现的错误!!
      

  6.   

    应该还要在显示子过程里进行记录集的EOF判断
      

  7.   

    对于你的问题首先给个建议:建议你使用数据对象connection和recordset对象。
    对于删除给你个通用代码:
    模块中:
    Public Function 删除信息(strsql As String)
    Debug.Print strsql
    On Error GoTo myerr
    If mycls.cn.State = adStateclose Then
     mycls.cn.Open
    End If
     mycls.cn.Execute (strsql)
    If mycls.cn.State = adStateOpen Then
     mycls.cn.Close
    End If
     删除信息 = 1
    Exit Function
    myerr:
    If mycls.cn.State = adStateOpen Then
     mycls.cn.Close
    End If
     删除信息 = 0
    End Function
    类中:
    Public cn As New ADODB.Connection
    Private Sub Class_Initialize()
    cn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\BillDB.mdb"
    End Sub
    窗体事件中:
    if         Call 删除信息("delete from Department")=0 then
      msgbox "数据删除失败",vbokonly+32,"Message"
    end if
    call 数据显示("select * from Department")
      

  8.   

    我们在数据库操作中不建议使用eof 和bof 操作,以下两种情况使用eof和bof的
    1.数据上一条 下一条等操作
    If mycls.cn.State = adStateclose Then
      mycls.cn.Open
    End Ifmycls.cn.open 
    set rs=mycls.cn.execute("select * from department")
    if not rs.eof and not rs.bof then
      rs.movenext
      if rs.eof=true then
        rs.movelast
      end if
    endif
    If mycls.cn.State = adStateopen Then
     mycls.cn.close
    End If
    2.用于查找
    ....
    if not rs.eof and not rs.bof  then
      do while rs.eof=false 
       ...
       ...
       rs.movenext
      loop
    end if 
      

  9.   

    null主要是指字段中没有存储过任何数据,而""是存储过删除等为空可以使用这样判断
    if rs.fields("name")<>"" then
      ..
      ..
    end if
    可以解决上述问题