Quick Q about passing recordsets to functions (vba, DAO) (1 Viewer)

HalloweenWeed

Member
Local time
Today, 07:00
Joined
Apr 8, 2020
Messages
213
Hi,
I just ran into the situation where I may want to pass a couple of recordsets to a function/subroutine. Pardon me for asking, but when I google this I get hundreds of misses on the hits.
When you pass a recordset to a function/subroutine, I understand this is a copy, not a single shared recordset.
Does the recordset retain the same current record?
Do the bookmarks pass with the recordset?
I.e. if I set a bookmark before passing, will the function/subroutine be able to use it to set the proper active record?
If the recordset is created with SQL containing "ORDER BY," does the sort order remain in the copy?
I.e. if the sort order sets a specific record as the first record, is that record the first record on the copy?
Thank you in advance.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:00
Joined
Oct 29, 2018
Messages
21,358
When you pass a recordset to a function/subroutine, I understand this is a copy, not a single shared recordset.
That may not be entirely correct. It's possible it's actually a reference or pointer to the actual recordset object. In which case every property it has will be the same and can be changed.
 

sonic8

AWF VIP
Local time
Today, 12:00
Joined
Oct 27, 2015
Messages
998
When you pass a recordset to a function/subroutine, I understand this is a copy, not a single shared recordset.
This is incorrect. If you pass a recordset to another procedure it is actually the very same recordset.
 

HalloweenWeed

Member
Local time
Today, 07:00
Joined
Apr 8, 2020
Messages
213
This is incorrect. If you pass a recordset to another procedure it is actually the very same recordset.
That would simplify things quite a bit, as long as I am careful that the subroutine/function doesn't leave any crucial settings modified.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:00
Joined
May 21, 2018
Messages
8,463
When you pass any object you pass a pointer to the object. You do not pass the entire house only the address to the house. If you pass byRef you pass the pointer (address), if you pass byVal you pass a copy of the pointer. You never pass a "clone" of the object.
 

HalloweenWeed

Member
Local time
Today, 07:00
Joined
Apr 8, 2020
Messages
213
When you pass any object you pass a pointer to the object. You do not pass the entire house only the address to the house. If you pass byRef you pass the pointer (address), if you pass byVal you pass a copy of the pointer. You never pass a "clone" of the object.
Thank you, guys.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:00
Joined
Feb 19, 2002
Messages
42,981
Since the "passing" around tends to stay in the same module, I create private variables in the header of the module to hold the recordset. That way, all procedures in the module can work directly with the same recordset.
 

HalloweenWeed

Member
Local time
Today, 07:00
Joined
Apr 8, 2020
Messages
213
Since the "passing" around tends to stay in the same module, I create private variables in the header of the module to hold the recordset. That way, all procedures in the module can work directly with the same recordset.
Oh, I see, nice tip :) TY
 

Users who are viewing this thread

Top Bottom