I am trying to return the results of a stored procedure to a form. I managed to iterate the results using the ADO recordset, but cannot bind the results to the form.
Here is the VBA code:
Private Sub RetrieveSiteInformation() Dim cmd As New ADODB.Command Dim cnn As New ADODB.Connection Dim rs As ADODB.Recordset, f As ADODB.Field With cnn .Provider = "SQLOLEDB" .ConnectionString = "data source=UKFCSVR;initial catalog=ACACB;Trusted_Connection=Yes" .Open End With Dim param1 As ADODB.Parameter If Nz(txtSiteID_Search.Value, vbNullString) <> vbNullString Then Set param1 = cmd.CreateParameter("@SiteID", adBigInt, adParamInput) param1.Value = txtSiteID_Search.Value cmd.Parameters.Append param1 End If With cmd .ActiveConnection = cnn .CommandText = "spSiteInformation_Retrieve" .CommandType = adCmdStoredProc **' THIS FAILS** Me.Recordset = .Execute **' THIS LOOP WORKS FINE** ' Set rs = .Execute ' rs.MoveFirst ' For Each f In rs.Fields ' Debug.Print f.Name ' Next ' With rs ' Do While Not .EOF ' Debug.Print ![CompanyName] & " " & ![Postcode] ' .MoveNext ' Loop ' End With End With cnn.Close End Sub
sql-server stored-procedures ms-access
winshent
source share