每次运行时都会出现“Operation  is  not  allowed  when  the  object  is  open”  即:“ 系统打开时不容许操作”
请大家帮忙纠正!!!谢谢  我分析的原因:是不是我在其他窗体上也调用过该储存过程没有关闭,但我在别的地方都运行正常,调用完后也加上了 adoCon.Close 。还有个原因我在调用该存储过程的同时也用到了ADODC1。这是我模块的代码: 
Public adoCon As New ADODB.Connection      
Public adoRs As New ADODB.Recordset        
Public adoRs1 As New ADODB.Recordset      
Public adoRs2 As New ADODB.Recordset        Public Sub main()          
Dim temp As String 
temp = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ck;Data Source=liuping-727f568" 
adoCon.Open (temp) 
End Sub 
这是我窗体代码: 
Private Sub Command1_Click() 
Call main 
adoCon.Open "select * from pand" 
Set adoRs = adoCon.Execute("update pand set pand.本月返修入库=cryd.fx from pand,(select 料号,sum( 出入数量)as fx from cryd where datediff(m, 出入时间,getdate()) <=1 and 仓库号='" & Trim(Text1.Text) & "' and 出入类型 like '%返修入库'group by 料号) as cryd where pand.料号=cryd.料号") Set adoRs = adoCon.Execute("update pand set pand.本月领用出库=0-cryd.fx from pand,(select 料号,sum( 出入数量)as fx from cryd where datediff(m, 出入时间,getdate()) <=1 and 仓库号='" & Trim(Text1.Text) & "' and 出入类型 like '%领用出库'group by 料号) as cryd where pand.料号=cryd.料号  ") 还有多条像以上这样的更新语句,这里不一一列举,但语句绝对正确 
  adoCon.Close 
Adodc1.CommandType = adCmdText 
Adodc1.RecordSource = "select * from pand" 
Set DataGrid1.DataSource = Adodc1 
Adodc1.Refresh 
End Sub

解决方案 »

  1.   

    我这是数据的更新,其实也是一种储存,这个概念我也不清楚,但我不知道为什么运行的时候就会报错
    “Operation  is  not  allowed  when  the  object  is  open”,在线等待解决办法!!!
      

  2.   

    Public adoCon As New ADODB.Connection 
    你觉得下面2句那句有问题呢?temp = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ck;Data Source=liuping-727f568" 
    adoCon.Open (temp) 
    adoCon.Open "select * from pand"
      

  3.   

    但我把 adoCon.Open "select * from pand"  删了还是不行!!!
    请问这是为什么啊?
      

  4.   

    请在关闭Recordset   再执行下一个查询 
    adoRs.close ADO 不是 dao 或者RDO 不能省这个代码的