By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,218 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,218 IT Pros & Developers. It's quick & easy.

The object you entered is not a valid recordset property

P: 51
I have a subform, whose data source is a parametered stored procedure.
The following code is added in Form_open, but I always got the error msg 'the object you entered is not a valid recordset property'. I've read the disconnection problem that posted on MS website, however it seems not for my case. I tried cursor too, not work.
Any suggestions are very much appreciated~~

Expand|Select|Wrap|Line Numbers
  1. Private Sub WhoFinishedSubFormRequery()
  2. Dim sql As String
  3.     Dim cmd As ADODB.Command, rst As ADODB.Recordset
  4.     Set cmd = New ADODB.Command
  5.     cmd.ActiveConnection = CurrentProject.Connection
  6.     cmd.CommandText = "EXEC dbo.spWhoFinishedBySurveyAndYear '" & Me.surveyName & "'," & Me.surveyYear
  7.     cmd.CommandType = adCmdText
  8.     Set rst = cmd.Execute
  9.     Set Me![frmTrackingWhoFinished].Form.Recordset = rst //where the error is
  10.     Set rst = Nothing
  11.     Set cmd = Nothing
  12. End Sub
  13.  
Jul 30 '09 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,679
@anniebai
I think that you need a change in Syntax. The following code has been tested and is fully operational:
Expand|Select|Wrap|Line Numbers
  1. Dim cmd As ADODB.Command
  2. Dim rst As ADODB.Recordset
  3.  
  4. Set cmd = New ADODB.Command
  5.  
  6. With cmd
  7.   .ActiveConnection = CurrentProject.Connection
  8.   .CommandText = "spEmployees"
  9.   .CommandType = adCmdStoredProc
  10. End With
  11.  
  12. Set rst = cmd.Execute()
  13.  
  14. With rst
  15.   Do While Not .EOF
  16.     Debug.Print ![FirstName] & " " & ![LastName]
  17.       .MoveNext
  18.   Loop
  19. End With
  20.  
  21. DoCmd.OpenForm "frmEmployees", acNormal, , , acFormEdit, acHidden
  22. Set Forms!frmEmployees.Recordset = rst
  23. DoCmd.OpenForm "frmEmployees"
  24.  
  25. Set rst = Nothing
  26. Set cmd = Nothing
Aug 1 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.