Solved

Getting Run time error 2115 when setting form recordset

Posted on 2012-04-10
3
558 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

685 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