str3 = ""
Set rs3 = ExecuteSQL(str3, True)
       
        MsgBox "入院信息输入成功!按回车继续", 0 + 48, "成功"
        txtpID.Text = ""
        txtVisitID.Text = ""
        txtpSex.Text = ""
        TxtpName.Text = ""
        TxtFeeType.Text = ""
        txtAge.Text = ""上面的代码是正确的,我就想问一下,我想如果ExecuteSQL这个函数处理成功的时候再弹出对话框,如果不成功就弹出另外一个对话框。
    谢谢了

解决方案 »

  1.   

    if rs3=nothing then.....我猜这样
      

  2.   

    ExecuteSQL 是你自己写的函数吗?
    可否把代码贴出来?
      

  3.   

    Public Function ExecuteSQL(ByVal SQL As String, operState As Boolean) As ADODB.Recordset
       '执行 SQL 并返回 Recordset
       GetConnectString
       Dim cnn As ADODB.Connection
       Dim rst As ADODB.Recordset
       Dim sTokens() As String
      ' MsgString As String
       On Error GoTo ExecuteSQL_Error
       
       sTokens = Split(SQL)
       Set cnn = New ADODB.Connection
       cnn.Open ConnectString
       If InStr("INSERT,DELETE,UPDATE", _
          sTokens(0)) Then
          cnn.Execute SQL
          MsgString = sTokens(0) & _
             " query successful"
       Else
          Set rst = New ADODB.Recordset
          rst.Open SQL, cnn, _
             adOpenKeyset, _
             adLockOptimistic
          Set ExecuteSQL = rst
       '   MsgString = "查询到" & rst.RecordCount & _
       '      " 条记录 "
       End If
       operState = True
    ExecuteSQL_Exit:
       Set rst = Nothing
       Set cnn = Nothing
       Exit Function
       
    ExecuteSQL_Error:
       MsgBox Err.Description
       operState = False
       Set ExecuteSQL = Nothing
       Resume ExecuteSQL_Exit
    End Function
      

  4.   

    那直接判断 rs.EOF 就可以了
    记录为空时 rs.EOF=True
      

  5.   

    不是记录为空,我原来的SQL语句是一条insert语句,怎么又记录为空的情况?
      

  6.   

    不好意思没看清问题当数据库操作错误时 函数会返回 Nothing所以应该判断 rs3 是否等于 Nothing等于 Nothing 操作失败
      

  7.   


    str3 = ""
    Set rs3 = ExecuteSQL(str3, True)
    '若rs3处于关闭状态,说明执行不成功
    If rs3.State <> adStateClosed Then
       if rs3.RecordCount>0 then
          msgbox "执行成功,有记录"
       else
          msgbox "执行成功,无记录"
       end if
    else
       msgbox "执行不成功"
    end if可否?勿忘给分
      

  8.   

    如果把 operState 设为全局变量,operState 也标志了数据库操作的成功与否
      

  9.   

    if rs3=nothing then.....
    lz结贴吧....