0

我需要一种方法来返回受 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
4

1 回答 1

1

Connection,Database并且QueryDef都有一个.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
于 2013-09-09T22:19:07.660 回答