0

The following code run a stored procedure based on a combobox that is selected in a form. I need to display the results in a form in Access. Here is the code:

Dim Cmd1 As ADODB.Command
Dim lngRecordsAffected As Long
Dim rs1 As ADODB.Recordset
Dim intRecordCount As Integer
'-----
Dim cnnTemp As ADODB.Connection
Set cnnTemp = New ADODB.Connection
cnnTemp.ConnectionString = "DRIVER=SQL Server;SERVER=****;" & _
"Trusted_Connection=No;UID=****;PWD=****;" & _
"Initial Catalog=IKB_QA;"
'Open Connection
cnnTemp.Open
Set Cmd1 = New ADODB.Command
Cmd1.ActiveConnection = cnnTemp
'---
With Cmd1
Dim localv As Integer
localv = [Forms]![start]![Selection]![cat_code]
.CommandText = "dbo.ix_spc_planogram_match"
.CommandType = adCmdStoredProc
.Parameters.Refresh
.Parameters("@catcode").Value = localv

Set rs1.Open = Cmd1.Execute(localv)
End With
End Sub
4

1 回答 1

0

我不清楚你在这个问题的哪一部分遇到了麻烦,但也许它是绑定部分。

您可以使用以下代码将表单绑定到 ADO 记录集:

Set Me.Recordset = rs1

只需确保您的表单具有绑定到将在您的记录集中的字段的控件。

于 2012-07-13T21:22:09.847 回答