On Error GoTo error
    AccessCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\Ast2100.mdb" & ";Persist Security Info=False"
    MsgBox "成功"
    GoTo continue
error:
    MsgBox "连接失败"
    Exit Function
continue:成功之后还说失败,,,,,,,,什么阿什么破VB

解决方案 »

  1.   

    这样比较清晰:On Error GoTo error
        AccessCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\Ast2100.mdb" & ";Persist Security Info=False"
        MsgBox "成功"
        Exit Functionerror:
        MsgBox "连接失败"
        Exit Function
      

  2.   

    还有,你完全可以把continue的程序段 提到 MsgBox "成功" 前吧
      

  3.   


    关于错误可以用  Err.Number判断是什么错误
    error:
        Select Case Err.Number
            Case xxxx
                 '可以判断是什么错误
        End Select
      

  4.   


    给你们一段实例:(包括错误处理)
    Public Function OpenConnection() As String '打开数据库
        On Error GoTo SQLConErr
        With adoCN
            .CursorLocation = adUseClient
            .Provider = "sqloledb"
            .Properties("Data Source").Value = cNtServerName
            .Properties("Initial Catalog").Value = cDatabaseName
            .Properties("User ID") = cSQLUserName
            .Properties("Password") = cSQLPassword
            .Properties("prompt") = adPromptNever
            .ConnectionTimeout = 15
            .Open
            
            If .State = adStateOpen Then
                adoDateTime.Open "select getdate()", adoCN, adOpenStatic, adLockOptimistic
                cServerDate = Format(adoDateTime(0), "yyyy-mm-dd")
                cServertime = Mid(adoDateTime(0), 10)
            Else
                MsgBox "数据库连接失败,请找系统管理员进行检查 !", 16, cProgramName
                End
            End If
        End With
        
        SqlCommand.ActiveConnection = adoCN
        SqlCommand.CommandType = adCmdText
        Exit Function
    SQLConErr:
        Select Case Err.Number
            Case -2147467259
                MsgBox "找不到指定的SQL Server服务器或者数据库不存在,请重新设置!", vbExclamation
                F_SetSystem.Show 1
            Case -2147217843
                MsgBox "指定的SQL Server数据库用户不存在或口令错误,请重新设置!", vbExclamation
                F_SetSystem.Show 1
            Case Else
                MsgBox "数据环境连接失败,请找系统管理员进行检查 !", 16, cProgramName
        End Select
        OpenConnection
    End Function
      

  5.   

    On Error GoTo error
        AccessCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\Ast2100.mdb" & ";Persist Security Info=False"
        MsgBox "成功"
        GoTo continue
        exit function
    error:
        MsgBox "连接失败"
        Exit Function
    continue:
    exit function这句让你的程序跳出错误处理程序段
      

  6.   

    我不想exit function 下边还有很长的代码呢
      

  7.   

    Private Function YourFunctionName()
    On Error GoTo error
        AccessCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\Ast2100.mdb" & ";Persist Security Info=False"
        MsgBox "成功"
        
        其它处理代码
        exit function'这句让你的程序跳出函数
    error:
        MsgBox "连接失败"
    End Function
      

  8.   

    学习lihonggen0(李洪根,用.NET,标准答案来了) 中.........
      

  9.   

    我想判断,插入判断,更判断,删除判断,可是怎么弄阿,....要给用户提供正确的提示,可是如何做,error.num在哪里?
      

  10.   

    pageup(小元)最初提出的问题提供的代码没有错呀,只是不够清晰而已,GOTO语句就是指到哪里,就运行到哪里就是了,逻辑性很强的:)但是不建议用!
      

  11.   

    On Error GoTo error
        AccessCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path + "\Ast2100.mdb" & ";Persist Security Info=False"
        MsgBox "成功"
        GoTo continue
        Exit Function
    error:
        MsgBox "连接失败"
        Exit Function
    continue:妈的,还是不行,老是连接失败...