0

I have an access 2010 and I want to call a sql stored proc on a sql 2008 server and return the results to a recordset or bind directly to a report.

The method below returns the error "feture not available in ADP" or something like that - It works with a Form but not with a Report.

How do I go about doing this?

Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim cm As New ADODB.Command

'Use the ADO connection that Access uses
Set cn = CurrentProject.AccessConnection
With cn
    .Provider = "Microsoft.Access.OLEDB.10.0"
    .Properties("Data Provider").Value = "SQLOLEDB"
    .Properties("Data Source").Value = "dsidsw923"
    .Properties("Integrated Security").Value = "SSPI"
    .Properties("Initial Catalog").Value = "Promotions_Dev_DSI"
    .Open
End With

'Create an instance of the ADO Recordset class, and
'set its properties
Set rs = New ADODB.Recordset

With cm
    .ActiveConnection = cn
    .CommandText = "spCheckProdWkConsist"
    .CommandType = adCmdStoredProc

    Set rs = .Execute()
End With

'Set the form's Recordset property to the ADO recordset
Set Me.Recordset = rs

Set rs = Nothing
Set cn = Nothing
Set cm = Nothing
1

1 Answer 1

0

Consider creating a view to wrap the results of the stored procedure (exec usp_whatever) and then create a linked table to the new view.

Also, you may be able to create a passthrough query (exec usp_whatever) that executes your stored procedure and returns your results directly. Then just bind your report or form to the query.

2
  • You can`t select * from a stored procedure. If you can provide code sample of passthrough query that would be helpful, thanks.
    – Perplexed
    Jan 31, 2012 at 21:56
  • OK, then you can wrap the exec in a view, or use the passthrough query.
    – Beth
    Jan 31, 2012 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.