Access PassThrough Query not returning correct number of records

I have an After Update Method:
Private Sub TurtleName_AfterUpdate()
     'Find the record that matches the control.
   
    Dim rs As Object
    Dim vTurtleID As Variant
    Dim strSQL As String
    Dim rsFeeding As Object
    Dim dbsql As Database

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[TurtleId] = " & Str(Nz(Me![TurtleName], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    vTurtleID = Me![TurtleName]

    'SQL Server PassThrough query
    Set dbsql = DBEngine.Workspaces(0).OpenDatabase _
      ("", False, False, "ODBC;DRIVER=SQL Server Native Client 11.0;SERVER=WIN7DEV\SQLEXPRESS2012;UID=David Blankman;Trusted_Connection=Yes;DATABASE=TurtlesDB_beSQL;")
    strSQL = "spSubFeeding " & vTurtleID & " "
    Set rsFeeding = dbsql.OpenRecordset(strSQL, dbOpenSnapshot, dbSQLPassThrough)
   
    Set Forms!TurtleMain!TurtleFeedingSub.Form.Recordset = rsFeeding
   
    TurtleChosen
   
 'dbsql.Close
   
End Sub

When I run the stored procedure from SSMS, I get 2200 records. When I run it inside Access it returns only one record.

Also, after I run the code once, it won't let me run it with another TurtleID. I thought that, perhaps, I should close the connection. I tried doing a dbsql.Close, but that seems to close the recordset as well.

Another thought that I had was defining the vTurtleID as a global variable and then assigning the recordset in the subform's onload event, although, I don't know if that would make any difference.
dblankmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
Check the parameter you are sending to the stored procedure..just copy paste the strsql output from your immediate window to SSMS to see what you are requesting....
Also check this article to see if something is missing
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
When using a Recordset as a Form's source, you must build it correctly. I've always used ADO recordsets for this, since for the most part you're going to be using SQL-based data in these cases. See this code adapted from https://support.microsoft.com/en-us/kb/281998:

Dim rst As ADODB.Recordset
Dim con As New ADODB.Connection
con.ConnectionString = "Your Connection STring"
con.Open

Set rs = New ADODB.Recordset
With rs
   Set .ActiveConnection = con
   .Source = ""spSubFeeding " & vTurtleID
   .LockType = adLockOptimistic
   .CursorType = adOpenKeyset
   .CursorLocation = adUseClient
   .Open
End With

Set me.Recordset = rst

You'd have to incorporate your RecordsetClone method to get the right TurtleID before running that block of code.

Note the link above specified 2003, but nothing has changed in regard to this in later versions.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dblankmanAuthor Commented:
Only one problem, you had this syntax: Set me.Recordset = rest, when the form to be changed as a subform.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

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.