Solved

Getting Run time error 2115 when setting form recordset

Posted on 2012-04-10
3
554 Views
Last Modified: 2012-04-16
Hello,

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
cnn.Open

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")  
 
    rst.Close
    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing
    Set objCmd = Nothing
   
End Sub
0
Comment
Question by:chtullu135
  • 2
3 Comments
 
LVL 40

Expert Comment

by:als315
ID: 37831215
You should run this code from opened form (in this case you will have Me). May be in On Open event.
http://support.microsoft.com/kb/281998/en-us
0
 

Accepted Solution

by:
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.
0
 

Author Closing Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

856 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