Results 1 to 2 of 2
  1. #1

    Passing a RecordSet to a public/private function


    I'm wondering what happens if I pass a recordset to a function. Is the currently selected row maintained in the recieving function?

    For instance:

    private function1 ()
    dim MyRecord as Recordset
    set MyRecord = db.OpenRecordset(SomeQuery, dbOpenSnapshot)
    MyRecord.Seek "=" Field1, Field2


    end sub

    public function DoSomething(anyRecord as RecordSet)
    end function

    Is the pointer or current record in DoSomething?

    I don't need to update MyRecord just process something based on values of some of the fields.


  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Passing a RecordSet to a public/private function

    When you pass a recordset, you pass the whole thing. If you want to pass just the current record, create a new recordset object and set it to the original recordset filtered down to the current record. So you might do something like this on an existing DAO recordset, rstCurrent:

    Dim rstFiltered as DAO.Recordset

    'filter the current recordset
    rstCurrent.filter ="[MyKeyField]=" & rstCurrent!MyKeyField
    'open a new recordset on the filter
    set rstFiltered = rstCurrent.OpenRecordset(dbOpenSnapshot)

    Then you could pass rstFiltered to another routine and there would only be a single record for it to work with, so you wouldn't have to worry about a pointer to the current record.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts