Getting Run time error 2115 when setting form recordset

Posted on 2012-04-10
Medium Priority
Last Modified: 2012-04-16

I am trying to set the recordset of a form via a stored procedure but I keep getting a '2115' error Method 'recordset of object" failed on the following line "Set Me.Recordset = rst".  The code works fine until that point.  

Public Sub ApplyReviewFilter()

Dim objCmd As ADODB.Command
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim prm As ADODB.Parameter

Dim strReview As String

strReview = Nz(Me.cmbSelectReview, "")

Set cnn = New ADODB.Connection

cnn.ConnectionString = cStrOLEDBConnectionString

Set objCmd = New ADODB.Command
cnn.CursorLocation = adUseClient

Set rst = New ADODB.Recordset

With objCmd
    .ActiveConnection = cnn
    .CommandText = "dbo.spRetrieveByReview"
    .CommandType = adCmdStoredProc
    .CommandTimeout = 3600
    Set prm = .CreateParameter("pReview", adVarChar, adParamInput, 500, strReview)
    .Parameters.Append prm
End With
    With rst
        .ActiveConnection = cnn
        .CursorType = adOpenStatic
    End With  
    Set rst = objCmd.Execute
    Set Me.Recordset = rst
    objCmd.Parameters.Delete ("pReview")  
    Set rst = Nothing
    Set cnn = Nothing
    Set objCmd = Nothing
End Sub
Question by:chtullu135
  • 2
LVL 41

Expert Comment

ID: 37831215
You should run this code from opened form (in this case you will have Me). May be in On Open event.

Accepted Solution

chtullu135 earned 0 total points
ID: 37832786
I found the problem.  I was inadvently calling the procedure from the before update event of a command button instead of the afterupdate event. It was a dumb mistake on my part.

Author Closing Comment

ID: 37850305
I found the solution on my own.  It was caused by calling the procedure from the wrong event of the command button

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question