Use Stored Procedure Results as a Microsoft Access Form Record Source
Question details
Display the results of a stored procedure in a Microsoft Access form.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A form needs to show records returned by a stored procedure.
- Observed behavior
- Assigning a recordset object to Me.RecordSource produces an "Invalid use of property" error.
Confirm that the stored procedure returns a result set and that you have permission to execute it. Check that the form's bound controls use field names returned by the procedure.
Assign an ADO Recordset to the Access Form
Use the form's Recordset property when VBA executes the stored procedure and receives an ADO recordset.
RecordSource expects a table name, query name, or SQL statement. An open recordset object must instead be assigned with Set Me.Recordset = rs.
The example uses SQL Server and a parameterless stored procedure. Replace the server, database, and procedure names, and install the specified OLE DB provider if necessary.
Open the form in Design View, open its Property Sheet, and clear the Record Source property if it is not needed. Check that each bound control's Control Source matches a returned field.
Open the VBA editor with Alt+F11. Select Tools > References and enable a Microsoft ActiveX Data Objects library.
In the form's VBA module, add the following code. Keep the connection and recordset at module scope so they remain available while the form is open: Private cn As ADODB.Connection Private rs As ADODB.Recordset Private Sub Form_Open(Cancel As Integer) Dim cmd As ADODB.Command Set cn = New ADODB.Connection cn.Open "Provider=MSOLEDBSQL;Data Source=YOUR_SERVER;" & _ "Initial Catalog=YOUR_DATABASE;Integrated Security=SSPI;" Set cmd = New ADODB.Command Set cmd.ActiveConnection = cn cmd.CommandType = adCmdStoredProc cmd.CommandText = "dbo.YourProcedure" Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient rs.Open cmd, , adOpenStatic, adLockReadOnly Set Me.Recordset = rs End Sub
Save the form, open it in Form View, and confirm that the returned fields and records appear. If the procedure requires parameters, add them to cmd.Parameters before rs.Open.

Use an Access Pass-Through Query as the Form Record Source
Use a saved pass-through query when you prefer to bind the form to a query name instead of assigning a recordset in VBA.
Work With Office Files in WPS Office
WPS Office is a free, lightweight alternative for working with documents and spreadsheets in a familiar interface. Its Microsoft Office format support helps you move existing files into your workflow. WPS Office does not run Access forms or fix Access recordset errors.

Frequently Asked Questions
Why does Set Me.RecordSource = rs cause an error?
RecordSource takes a table name, query name, or SQL statement, not a recordset object. Assign an open recordset with Set Me.Recordset = rs instead.
Can I use a DAO recordset with an Access form?
Yes. Open a DAO recordset with CurrentDb.OpenRecordset, then assign it using Set Me.Recordset = rs. A recordset opened with dbOpenSnapshot is read-only.
How can I run a stored procedure without assigning a recordset in VBA?
Create an Access pass-through query containing the procedure's execution command, configure its ODBC Connect Str and Returns Records properties, and set the form's Record Source to the saved query name.
Why are my form controls blank after binding the results?
In Design View, check each control's Control Source against the field names returned by the stored procedure. Also run the procedure or pass-through query separately to confirm that it returns records.




