[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

Getting Run time error 2115 when setting form recordset

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
chtullu135
Asked:
chtullu135
  • 2
1 Solution
 
als315Commented:
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
 
chtullu135Author Commented:
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
 
chtullu135Author Commented:
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now