我在VB中做打印报表,以下是一个按钮事件中的代码,但重复点击会报错:对象关闭时操作不被允许!
如果把DataE1.rsCommand1.Close注释掉,可以避免,但是点击别的报表按钮后再点击这个按钮又会报错,请问我该怎么办?
If DataE1.Connection1.State = 0 Then
   DataE1.rsCommand1.Open "select * from data where 运单号码 ='" & yd & "'"
   DR1_data.Show
Else
   DataE1.rsCommand1.Close
   DataE1.rsCommand1.Open "select * from data where 运单号码 ='" & yd & "'"
   DR1_data.Show
End If

解决方案 »

  1.   

    如果
    DataE1.rsCommand1.state=0
    DataE1.rsCommand1.close
      

  2.   

    if DataE1.rsCommand1.state=1 then DataE1.rsCommand1.close
      

  3.   

    按skywolfY(莫愁)的方法应该没有问题吧!
    解释:如果对象是打开的则关闭,明白了吗?
      

  4.   

    If DataRep.DataRep.State Then DataRep.DataRep.Close'判断DataRep.DataRep是否打开,打开则关闭(设计时数据连接)
    DataRep.DataRep.ConnectionString = adoConnect'连接数据库字符串,调用FunctionSet wzReport.DataSource = ado_Grid'将wzReport.DataSource重新连接到新的数据源(ado控件产生)
    wzReport.DataMember = ""
    If DataRep.rswzRep.State Then DataRep.rswzRep.Close
       wzReport.Sections(2).Controls("label3").Caption ="hello"'为DataReport设计器中label3赋值(Caption)
                                                    
    wzReport.Refresh'刷新
    wzReport.Show 1'显示
    Public Function adoConnect() As String
        adoConnect = "Provider=MSDASQL.1;Password=1234;Persist Security Info=True;User ID=sa;Data Source=Dkh_fx"
    End Function
      

  5.   

    If DataRep.DataRep.State Then DataRep.DataRep.Close'判断DataRep.DataRep是否打开,打开则关闭(设计时数据连接)DataRep.DataRep.Close关闭数据库连接