你应该在本程序段末尾处加入以下语句
sqlerr:
    exit sub'或其它的语句,以便在程序出错时跳到本处以处理发生的错误
例如:
sqlerr:
    msgbox "你的程序出错了!"'进行报警

解决方案 »

  1.   

    On Error Goto 是发生错误时跳转到你自已的处理程序段Private Sub Command1_Click()
    Dim linkFlag As String
    Dim strSql As String
    Dim strwhere As String
    Dim i As Integer
     
    For i = 0 To 8
    If Trim(Text1(i).Text) <> "" Then
    strwhere = strwhere & Label1(i).Caption & "" & "=" & "" & "'" & Text1(i).Text & "'"
    strSql = "Select * from quantity where" & "" & strwhere
    End If
    Next ilinkFlag = FunSqlLink
    Set Rs = New ADODB.Recordset
    On Error GoTo sqlerr       '如果发生错误则跳转到sqlerr标号处
    Rs.Open strSql, Cnn, adOpenDynamic, adLockReadOnly
    .
    .
    .
    sqlerr:                 '定义标号,
        '错误处理代码