MS-Access 2013将存储过程结果连接到组合框记录集

时间:2015-08-28 12:43:53

标签: vba ms-access adodb

AS在主题中,我需要将存储过程结果连接为记录集。用一些例子我发现我提出了:

Dim cn As New ADODB.Connection
cn = GetConnection()
Dim cmd As New ADODB.Command

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With cmd
 .ActiveConnection = GetConnection()
 .CommandText = "dbo.K_Kod_Agenta_P"
 .CommandType = adCmdStoredProc

 .Parameters.Refresh
End With
With rs
.ActiveConnection = GetConnection()
.CursorType = adOpenForwardOnly
.CursorLocation = adUseServer

End With

Set rs = cmd.Execute


Set Me.kod_nadagenta.Recordset = rs

rs.Close
cn.Close

但是当它击中时

Set Me.kod_nadagenta.Recordset = rs

它抛出

"运行时错误' 7965':您输入的对象不是有效的Recordset属性。"

1 个答案:

答案 0 :(得分:1)

使用以下SQL创建传递查询:

dbo.K_Kod_Agenta_P

现在只需将组合框基于该传递查询。您不需要所有代码。