我需要一种方法来返回受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
答案 0 :(得分: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