当打开一个已经打开的ACCESS库时出错,如果在程序里判断打开库出错,并提醒用户关闭正在打开着的库。
不可以使用On Error GoTo error1这类语句,使用if  .... then   ...解决后即刻给分。

解决方案 »

  1.   

    "不可以使用On Error GoTo error1这类语句,使用if  .... then   ..." why?关闭和打开数据库,应该是程序里做的事,为什么要提示用户来做?
      

  2.   

    victorycyz(中海,干活去,别在CSDN玩耍!) 你改个名行吗?我以为在说我哪
      

  3.   

    ffly(鱼),我是在说我自己呐。没看前面有个称呼“中海”吗。
      

  4.   

    If Conn.status = 1 Then
        MsgBox "数据库已经打开"
    End If在执行打开操作前加上这句。
      

  5.   

    最好用On Error GoTo error1if Err then
       conn.close
       set conn=nothing
       msgbox "数据库已关闭!"
       .......end if
      

  6.   

    我使用的是data控件打开数据库
      

  7.   

    dim cn as new adodb.connectionif cn.state=adstateopen then 
    if msgbox ("数据库已经连接,要关闭吗",vbYesNo )=vbYes then 
       cn.close
       cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp.mdb;Persist Security Info=true" 
    end if
      

  8.   

    楼主使用的是DAO,大家怎么都教使用ADO的方法?
      

  9.   

    晕自从用了ado就不想用dao了
    1爱作   2倒
      

  10.   

    如果出错要提醒的话,只能用on error
      

  11.   

    '设置数据库
      Data1.DatabaseName = App.Path & "\" & "bast.mdb"
      Data1.Connect = ";pwd=28Fr"
      Data1.RecordSource = "select * from table"
      

  12.   

    '判断数据库是否打开出错
    On Error GoTo errhandle
    Data1.DatabaseName = App.Path & "\" & "bast.mdb"
    Data1.Connect = ";pwd=28Fr"
    Data1.RecordSource = "select * from table"Exit Sub
    errhandle:
    MsgBox "Please Close!"
    End如上写并不行。
      

  13.   

    On Error GoTo error1
    cnn.Open ConnectString
    error1:
      msgbox "connect error"
      if  msgbox( "是否要关闭连接",vbyesno,"")=vbyes then
          set cnn= nothing
      endif
      

  14.   

    if cn.state=adstateopen then 
    if msgbox ("数据库已经连接,要关闭吗",vbYesNo )=vbYes then 
       cn.close
       cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp.mdb;Persist Security Info=true" 
    end if