With g_Conn
    .ConnectionString = "Data Source=equip"
    .Open
  End With
g_Conn是一全局变量Private Sub AddNewOper()
  Dim rs_OperEquip As New ADODB.Recordset
  
  Dim rs_Oper As New ADODB.Recordset
    
 rs_Oper.Open "operinfo", g_Conn, adOpenKeyset, adLockOptimistic  g_Conn.BeginTrans
  With rs_Oper
    .Filter = "operid='" & txtOperId & "'"
    If .BOF And .EOF Then
      .AddNew
      !OperId = txtOperId
      !oname = txtOperName
      .Update
      'MsgBox "操作者编号已经存在请确定输入正确", vbCritical, "Alarm"
      '.Close
      'Set rs_Oper = Nothing
      'Exit Sub
    End If
    '.AddNew
    '!OperId = txtOperId
    '!oname = txtOperName
    '!eqid = txtEqId
    '!proline = txtProLine
    
  End With
  With rs_OperEquip
    .Open "operequip", g_Conn, adOpenKeyset, adLockOptimistic
    .AddNew
    !OperId = txtOperId
    !eqid = txtEqId
    !proline = txtProLine
    .Update
  End With
  cnn_Oper.CommitTrans
  
End Sub

解决方案 »

  1.   

    从代码上看没问题,不过
    With g_Conn
        .ConnectionString = "Data Source=equip"
        .Open
      End With
    打开是不是运行正确?
      

  2.   

    哦,那就不清楚了,没见过这种错误,你可以用ODBC的方式看是否还有这个错误,如果没有说明是连接字符串的问题。
      

  3.   

    但是很奇怪我在另外一个窗口中却没有出错(我的程序有很多个form)
    不同的是我是另外定义了connection对象在form1中代码如下:
    private cnn as new adodb.connectionPrivate Sub AddNewOper()
      Dim rs_OperEquip As New ADODB.Recordset
      
      Dim rs_Oper As New ADODB.Recordset With Cnn
        .ConnectionString = "Data Source=equip"
        .Open
      End With  
     rs_Oper.Open "operinfo", Cnn, adOpenKeyset, adLockOptimistic  Cnn.BeginTrans
      With rs_Oper
        .Filter = "operid='" & txtOperId & "'"
        If .BOF And .EOF Then
          .AddNew
          !OperId = txtOperId
          !oname = txtOperName
          .Update
        End If  End With
      With rs_OperEquip
        .Open "operequip", Cnn, adOpenKeyset, adLockOptimistic
        .AddNew
        !OperId = txtOperId
        !eqid = txtEqId
        !proline = txtProLine
        .Update
      End With
      cnn.CommitTrans
      
    End Sub