我现在要实现的功能是:
1、寻找是否存在该数据库;
2、打开该数据库,如果损坏,看是否在这个环节就会被拦截;
3、在一个循环中遍历数据表,查看是否有某个数据表损坏,然后提示,并拦截错误,如果没有检查完,不跳出循环,继续检查其他的数据表。现在被错误处理搞得头疼,虽然有on error 的处理,不过他还是会弹出一个错误提示框,程序就崩溃了,请问如何解决?

解决方案 »

  1.   

    把你的on error 代码贴上来,感觉你写的不对。
      

  2.   

    用on error goto 了么〉?
    一旦有错误就跳出检查并抱错。。
      

  3.   

    For i = 0 To UBound(s) - 1
        
        cFullPath = "\\" & cIP & cSvrPath & s(i) & "\" _
            & cYear & "\UFDATA.MDB"
        
        On Error GoTo checkdatabase
        
        If Len(Dir(cFullPath)) > 0 Then        If Len(Dir("\\" & cIP & cSvrPath & s(i) & "\" & cYear & _
                "\UFDATA.ldb")) = 0 Then
                
            cConString = "provider=microsoft.jet.oledb.3.51;" _
                & "data source=" & cFullPath
                
            If Len(cDataPwd) > 0 Then
                cConString = cConString & ";Jet OLEDB:Database password=" & cDataPwd
            End If
            
            oCN.ConnectionString = cConString
            oCN.Open
            
            Set oRS = oCN.OpenSchema(adSchemaTables, _
                Array(Empty, Empty, Empty, "Table"))
            
                If oRS.RecordCount > 0 Then
                oRS.MoveFirst
          
                '遍历所有数据表
                Do While Not oRS.EOF
                    
                    cFileName = oRS.Fields(2)
                    If Left(cFileName, 4) = "MSys" Then
                        oRS.MoveNext
                        cFileName = oRS.Fields(2)
                    End If
                    cQryString = "select count(*) from [" & cFileName & "]"
                    o.Open oCN, cQryString
                    o.Close
                    oRS.MoveNext
                Loop            oRS.Close
                oCN.Close
        txtshow.text="..."
                End If
            Else
                txtShow.Text = "..."
            End If
        Else
            txtShow.Text = "..."
             s(i) = ""
            DoEvents
        End If
    checkdatabase:
    If Err.Number > 0 Then
        txtShow.Text = "..."
        Err.Clear
        oRS.Close
        oCN.Close
        s(i) = ""
        Resume next
    End IfNext有点乱,麻烦看一下,谢谢啦。