实时错误’-2147217887(80040e21)’:
多步OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成。
这个错误是因为没连接数据库吗?

解决方案 »

  1.   

    刚才怎么打不开网页
    代码是Private Sub Form_Load()
    Dim MsgText As String
    Dim intCount As Integer
    With cboitem
        cboitem.AddItem "男"
        cboitem.AddItem "女"
    End With
    If gintMode = 1 Then
        Me.Caption = Me.Caption & "添加"
        cboitem.ListIndex = 0
    ElseIf gintMode = 2 Then
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        If mrc.EOF = False Then
        With mrc
             For intCount = 0 To 2
                 txtItem(intCount) = .Fields(intCount)
             Next intCount
             If Not IsNull(!ygsex) Then
                   cboitem = !ygsex
             End If
             For intCount = 3 To 18
                 If Not IsNull(.Fields(intCount + 1)) Then
                        txtItem(intCount) = .Fields(intCount + 1)
                 End If
             Next intCount
        End With
        txtItem(0).Enabled = False
        End If
    mrc.Close
    Me.Caption = Me.Caption & "修改"
    End If
    mblChange = False
    End SubPrivate Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
    EnterToTab KeyCode
    End SubPrivate Sub cmdExit_Click()
    If mblChange And CmdSave.Enabled Then
       If MsgBox("保存当前记录的变化吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
          Call CmdSave_Click
       End If
    End If
    Unload Me
    End SubPrivate Sub CmdSave_Click()
          Dim intCount As Integer
          Dim txtSQL As String
          Dim MsgText As String
          Dim sMeg As String
          Dim i As Integer
          For intCount = 0 To 2
              If Trim(txtItem(intCount) & "") = "" Then
                 Select Case intCount
                        Case 0
                             sMeg = "编号"
                        Case 1
                             sMeg = "姓名"
                        Case 2
                             sMeg = "部门"
                 End Select
                 sMeg = sMeg & "不能为空!"
                 MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
                 txtItem(intCount).SetFocus
                 Exit Sub
              End If
           Next intCount
           If Trim(txtItem(3) & "") <> "" Then
            If Not IsDate(txtItem(3)) Then
                   MsgBox "生日应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                   txtItem(3).SetFocus
                   Exit Sub
            Else
                   txtItem(3) = Format(txtItem(3), "yyyy-mm-dd")
            End If
           End If
            If Trim(txtItem(7) & "") <> "" Then
            If Not IsDate(txtItem(7)) Then
                   MsgBox "参加工作时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                   txtItem(7).SetFocus
                   Exit Sub
            Else
                   txtItem(7) = Format(txtItem(7), "yyyy-mm-dd")
            End If
           End If
           
             If Trim(txtItem(8) & "") <> "" Then
            If Not IsDate(txtItem(8)) Then
                   MsgBox "入党时间时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                   txtItem(8).SetFocus
                   Exit Sub
            Else
                   txtItem(8) = Format(txtItem(8), "yyyy-mm-dd")
            End If
           End If
            If Trim(txtItem(10) & "") <> "" Then
            If Not IsDate(txtItem(10)) Then
                   MsgBox "职称时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                   txtItem(10).SetFocus
                   Exit Sub
            Else
                   txtItem(10) = Format(txtItem(10), "yyyy-mm-dd")
            End If
           End If
            If Trim(txtItem(14) & "") <> "" Then
            If Not IsDate(txtItem(14)) Then
                   MsgBox "进入公司时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                   txtItem(14).SetFocus
                   Exit Sub
            Else
                  txtItem(14) = Format(txtItem(14), "yyyy-mm-dd")
            End If
           End If
            If Trim(txtItem(15) & "") <> "" Then
            If Not IsDate(txtItem(15)) Then
                   MsgBox "起薪时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                   txtItem(15).SetFocus
                   Exit Sub
            Else
                   txtItem(15) = Format(txtItem(15), "yyyy-mm-dd")
            End If
           End If
            If Trim(txtItem(16) & "") <> "" Then
            If Not IsDate(txtItem(16)) Then
                   MsgBox "调入时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                   txtItem(16).SetFocus
                   Exit Sub
            Else
                   txtItem(16) = Format(txtItem(16), "yyyy-mm-dd")
            End If
           End If
           If gintMode = 1 Then
              txtSQL = "select* from manrecord where ygid=" & Trim(txtItem(0)) & ""
              Set mrc = ExecuteSQL(txtSQL, MsgText)
              If mrc.EOF = False Then
                 MsgBox "已经存在此员工档案编号的记录!", vbOKOnly + vbExclamation, "警告"
                 txtItem(0).SetFocus
                 txtItem(0).SelStart = 0
                 txtItem(0).SelLength = Len(txtItem(0))
                 Exit Sub
              End If
              mrc.Close
            End If
            txtSQL = "delete from manrecord where ygid=" & Trim(txtItem(0)) & ""
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            txtSQL = "select* from manrecord"
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            mrc.AddNew
            For intCount = 0 To 2
                mrc.Fields(intCount) = Trim(txtItem(intCount))
            Next intCount
            mrc.Fields(3) = Trim(cboitem.Text)
            For intCount = 3 To 18
               mrc.Fields(intCount + 1) = Trim(txtItem(intCount))
           Next intCount
            mrc.Update
           If gintMode = 1 Then
               MsgBox "记录添加成功!", vbOKOnly + vbExclamation, "警告"
               For i = 0 To 18
                   txtItem(i).Text = ""
                   mblChange = False
               Next i
               'frmManRecord1.Show
               'frmManRecord1.ZOder 0
               'frmManrecord.ShowTitle
               'frmManrecord.ShowData
               'frmManrecord.ZOder 1
            Else
               MsgBox "记录修改成功!", vbOKOnly + vbExclamation, "警告"
               Unload Me
                'frmManrecord.ShowTitle
                'frmManrecord.ShowData
                'frmManrecord.ZOder 0
            End If
            gintMode = 0
    End Sub
      

  2.   

    检查下变量数据类型、或者是否null
      

  3.   

    给每一个字段赋值的代码那里,for循环那个位置出错,
    mrc.Fields(intcount)=Trim(txtItem(intcount))
    是这句有问题吗?
      

  4.   

    格式化一下Private Sub Form_Load()
        Dim MsgText As String
        Dim intCount As Integer
        
        With cboitem
            cboitem.AddItem "男"
            cboitem.AddItem "女"
        End With
        
        If gintMode = 1 Then
            Me.Caption = Me.Caption & "添加"
            cboitem.ListIndex = 0
        ElseIf gintMode = 2 Then
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            
            If mrc.EOF = False Then
                With mrc
                    For intCount = 0 To 2
                        txtItem(intCount) = .Fields(intCount)
                    Next intCount
                    
                    If Not IsNull(!ygsex) Then
                        cboitem = !ygsex
                    End If
                    
                    For intCount = 3 To 18
                        If Not IsNull(.Fields(intCount + 1)) Then
                            txtItem(intCount) = .Fields(intCount + 1)
                        End If
                    Next intCount
                End With
                
                txtItem(0).Enabled = False
            End If
            
            mrc.Close
            Me.Caption = Me.Caption & "修改"
        End If
        
        mblChange = False
        
    End Sub
        
    Private Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
        EnterToTab KeyCode
        
    End Sub
        
    Private Sub cmdExit_Click()
        If mblChange And CmdSave.Enabled Then
            If MsgBox("保存当前记录的变化吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
                Call CmdSave_Click
            End If
        End If
        
        Unload Me
        
    End Sub
        
    Private Sub CmdSave_Click()
        Dim intCount As Integer
        Dim txtSQL As String
        Dim MsgText As String
        Dim sMeg As String
        Dim i As Integer
        
        For intCount = 0 To 2
            If Trim(txtItem(intCount) & "") = "" Then
                Select Case intCount
                    Case 0
                        sMeg = "编号"
                    Case 1
                        sMeg = "姓名"
                    Case 2
                        sMeg = "部门"
                End Select
                
                sMeg = sMeg & "不能为空!"
                MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
                txtItem(intCount).SetFocus
                Exit Sub
            End If
        Next intCount
        
        If Trim(txtItem(3) & "") <> "" Then
            If Not IsDate(txtItem(3)) Then
                MsgBox "生日应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                txtItem(3).SetFocus
                Exit Sub
            Else
                txtItem(3) = Format(txtItem(3), "yyyy-mm-dd")
            End If
        End If
        
        If Trim(txtItem(7) & "") <> "" Then
            If Not IsDate(txtItem(7)) Then
                MsgBox "参加工作时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                txtItem(7).SetFocus
                Exit Sub
            Else
                txtItem(7) = Format(txtItem(7), "yyyy-mm-dd")
            End If
        End If
        
        If Trim(txtItem(8) & "") <> "" Then
            If Not IsDate(txtItem(8)) Then
                MsgBox "入党时间时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                txtItem(8).SetFocus
                Exit Sub
            Else
                txtItem(8) = Format(txtItem(8), "yyyy-mm-dd")
            End If
        End If
        
        If Trim(txtItem(10) & "") <> "" Then
            If Not IsDate(txtItem(10)) Then
                MsgBox "职称时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                txtItem(10).SetFocus
                Exit Sub
            Else
                txtItem(10) = Format(txtItem(10), "yyyy-mm-dd")
            End If
        End If
        
        If Trim(txtItem(14) & "") <> "" Then
            If Not IsDate(txtItem(14)) Then
                MsgBox "进入公司时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                txtItem(14).SetFocus
                Exit Sub
            Else
                txtItem(14) = Format(txtItem(14), "yyyy-mm-dd")
            End If
        End If
        
        If Trim(txtItem(15) & "") <> "" Then
            If Not IsDate(txtItem(15)) Then
                MsgBox "起薪时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                txtItem(15).SetFocus
                Exit Sub
            Else
                txtItem(15) = Format(txtItem(15), "yyyy-mm-dd")
            End If
        End If
        
        If Trim(txtItem(16) & "") <> "" Then
            If Not IsDate(txtItem(16)) Then
                MsgBox "调入时间应输入日期(yyyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
                txtItem(16).SetFocus
                Exit Sub
            Else
                txtItem(16) = Format(txtItem(16), "yyyy-mm-dd")
            End If
        End If
        
        If gintMode = 1 Then
            txtSQL = "select* from manrecord where ygid=" & Trim(txtItem(0)) & ""
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            
            If mrc.EOF = False Then
                MsgBox "已经存在此员工档案编号的记录!", vbOKOnly + vbExclamation, "警告"
                txtItem(0).SetFocus
                txtItem(0).SelStart = 0
                txtItem(0).SelLength = Len(txtItem(0))
                Exit Sub
            End If
            
            mrc.Close
        End If
        
        txtSQL = "delete from manrecord where ygid=" & Trim(txtItem(0)) & ""
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        txtSQL = "select* from manrecord"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        mrc.AddNew
        
        For intCount = 0 To 2
            mrc.Fields(intCount) = Trim(txtItem(intCount))
        Next intCount
        
        mrc.Fields(3) = Trim(cboitem.Text)
        
        For intCount = 3 To 18
            mrc.Fields(intCount + 1) = Trim(txtItem(intCount))
        Next intCount
        
        mrc.Update
        
        If gintMode = 1 Then
            MsgBox "记录添加成功!", vbOKOnly + vbExclamation, "警告"
            
            For i = 0 To 18
                txtItem(i).Text = ""
                mblChange = False
            Next i
            
            frmManRecord1.Show
            frmManRecord1.ZOder 0
            frmManrecord.ShowTitle
            frmManrecord.ShowData
            frmManrecord.ZOder 1
        Else
            MsgBox "记录修改成功!", vbOKOnly + vbExclamation, "警告"
            Unload Me
            frmManrecord.ShowTitle
            frmManrecord.ShowData
            frmManrecord.ZOder 0
        End If
        
        gintMode = 0
        mrc.Close
    End Sub
     
      

  5.   

    最后应该加mrc.Close    gintMode = 0
        mrc.Close
    End Sub