Effects on RST in Calling Proc



Here's the scenario, A2003, Jet back end, illustrated with some cut down code at the end of the post:

A proc dims a snapshot recordset (dim rst as Dao.recordset) and opens it. There are several nested do loops, going through the records in rst using .movenext. At one point in one of the loops, we'll say the rst is at record "a". Now, another subprocedure is called, passing rst to it.

In the subprocedure, the recordset goes through a do loop and the sub evaluates each record for various criteria, again, using .movenext. By the time the subproc is done with the recordset, it is at the last record. We then go back to the calling proc.

Will the recordset in the calling procedure still be at record "a"? Or will it be at the end?

I've assumed the last is true and for now, in the main procedure, I figure dimming a second recordset and setting it to the same as the first. I thought using the second set would bypass any problems running through the recordset in the second procedure.

Thanks for any comments on this.

Sub sMainProc()

 dim rst as dao.recordset
 dim dbs as dao.database

 set dbs = access.currentdb
 set rst = dbs.openrecordset(<sql statement>, dbopensnapshot)

 with rst

  if .eof = false then

   .movefirst

   do while .eof = false

     <evaluate stuff, other loops, etc>

     'At this point, rst is at record "a"

     sMainProcOtherEval(rst)

     'Will rst still be at "a"?

     .movenext

   loop

  end if

  .close

 end with

end sub

sub sMainProcOtherEval(r as dao.recordset)

 with r 'start at beginning of passed rst

  .movefirst

  do while .eof = false

   <evaluate stuff, other loops, etc>

   .movenext

  loop

  .close

 end with

end sub
--
Tim   http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
.



Relevant Pages

  • Re: reusing command object
    ... the recordset and make updates to certain records. ... Dim cmd As New ADODB.Command ... Dim rst As ADODB.Recordset ... command object as its connection parameter. ...
    (microsoft.public.access.adp.sqlserver)
  • Re: reusing command object
    ... opening the recordset using the command object I want to move through the ... recordset and make updates to certain records. ... Dim cmd As New ADODB.Command ... "Dim rst As Recordset", its better to write "Dim rst As ...
    (microsoft.public.access.adp.sqlserver)
  • Re: too few parameters error
    ... You're trying to use DAO code below. ... did you remove the reference to ADO at the same time? ... Recordset is an object in both the DAO and ADO models. ... Dim rst As DAO.Recordset ...
    (microsoft.public.access.formscoding)
  • Re: reusing command object
    ... recordset and make updates to certain records. ... Dim cmd As New ADODB.Command ... Dim rst As ADODB.Recordset ... its better to write "Dim rst As ADODB.Recordset". ...
    (microsoft.public.access.adp.sqlserver)
  • Re: BOF EOF enabling cmd buttons
    ... DoCmd.GoToRecord doesn't actually do anything to your recordset. ... >> Dim Rst As DAO.Recordset ... >> 2) To instantiate your database object, ... (you need an OpenRecordset statement ...
    (microsoft.public.access.gettingstarted)