Bind Access form to the results from a Stored Procedure

后端 未结 3 1872
失恋的感觉
失恋的感觉 2021-01-05 15:32

I am trying to return the results of a stored procedure to a form. I have managed to iterate thru the results using an ADO recordset, but cannot bind the results to the form

3条回答
  •  -上瘾入骨i
    2021-01-05 15:47

    Okay, I have tested this example. It includes changes to suit my set-up which I have left in, rather than guessing at your set-up. Most of this is taken from http://support.microsoft.com/kb/281998/EN-US/

    Dim cn As New ADODB.Connection
    Dim cmd As New ADODB.Command
    Dim param1  As New ADODB.Parameter
    
        With cn
            .Provider = "Microsoft.Access.OLEDB.10.0"
            .Properties("Data Provider").Value = "SQLOLEDB"
            .Properties("Data Source").Value = "Server"
            .Properties("Integrated Security").Value = "SSPI"
            .Properties("Initial Catalog").Value = "Test"
            .Open
        End With
    
        txtSiteID_Search = 1
    
        If Nz(txtSiteID_Search, vbNullString) <> vbNullString Then
            Set param1 = cmd.CreateParameter("@SiteID", adBigInt, adParamInput)
            param1.Value = txtSiteID_Search
            cmd.Parameters.Append param1
        End If
    
        With cmd
            .ActiveConnection = cn
            .CommandText = "spSiteInformation_Retrieve"
            .CommandType = adCmdStoredProc
            Set Me.Recordset = .Execute
        End With
    

提交回复
热议问题