将受SQL Server 2008影响的记录返回到Access

时间:2013-09-09 19:12:55

标签: sql-server-2008 tsql vba ms-access

我需要一种方法来返回受SQL Server存储过程影响的记录,并使用我的Access数据库中的VBA将其显示在消息框中。以下是我用于在Access ...

中执行所有存储过程的过程
Public Sub SP(exec As String)
    Dim qdf As DAO.QueryDef
    Dim strConn As String

    strConn = "ODBC;DRIVER=SQL Server;SERVER=;DATABASE=;Trusted_Connection=Yes"

    Set qdf = CurrentDb.CreateQueryDef("")
    With qdf
        .Connect = strConn
        .ReturnsRecords = False
        .SQL = exec
        .Execute
        .Close
    End With
    Set qdf = Nothing
End Sub

1 个答案:

答案 0 :(得分:1)

ConnectionDatabaseQueryDef都有.RecordsAffected属性。

尝试以下方法:

Public Sub SP(exec As String)
    Dim qdf As DAO.QueryDef
    Dim strConn As String

    strConn = "ODBC;DRIVER=SQL Server;SERVER=;DATABASE=;Trusted_Connection=Yes"

    Set qdf = CurrentDb.CreateQueryDef("")
    With qdf
        .Connect = strConn
        .ReturnsRecords = False
        .SQL = exec
        .Execute
        MsgBox Exec & vbCrLf & vbCrLf & .RecordsAffected & " Record(s) Affected."
        .Close
    End With
    Set qdf = Nothing
End Sub