2015-08-28 52 views
1

因为在主题中,我需要将存储过程结果连接为记录集。用一些例子,我发现我想出了:MS-Access 2013将存储过程结果连接到组合框记录集

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

只需创建一个传递查询用下面的SQL:

dbo.K_Kod_Agenta_P 

现在只是立足于该传递查询组合框。你不需要所有的代码。

相关问题