What would be the preferred method in "passing" a DOA Recordset from one form to another.
1) Dim as DOA Recordset Public?
2) Reference via the Forms Collection?
3) Pass its name in OpenArgs?
4) None of the above
What would be the preferred method in "passing" a DOA Recordset from one form to another.
1) Dim as DOA Recordset Public?
2) Reference via the Forms Collection?
3) Pass its name in OpenArgs?
4) None of the above
I have used #1 to pass recordset between procedures.
Preference likely depends on circumstances.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
I won't take a position on "preferred". It probably depends on the overall situation and what you're trying to accomplish. Off the top of my head I'd probably declare the DAO recordset publicly. I'm not sure if you could pass the name of it in OpenArgs, though that's completely untested. I'm not sure how you'd then reference it In essence you'd be using a variable for the recordset name, and I can't visualize how that would work.
I had exactly the same question in my mind about any method involving the use of OpenArgs, not even sure what my test would look like at the moment. While I've had occasion to reference controls via referencing within the Forms collection in the past, I think a well placed comment in code added to a Public declaration in the calling form makes the most sense in my situation.
Ever onward! And, thanks to you both,
Bill
WELL RATS! I thought I knew what I was doing.
In calling form:In called form:Code:Public rsRegEMAs As DAO.RecordsetNeither of these references work, "rsRegEMAs" not defined in 1st case and field not found in 2nd case. (Funny thing though, the compiler knew to capitalize reRegEMAs when I coded rsregemas.recordcount)Code:MsgBox rsRegEMAs.RecordCount GOT IT! Just had a syntax errorMsgBox Forms("frmRegistry")!rsRegEMAs.RecordCountCode:Forms!frmRegistry.rsRegEMAs.RecordCount
The recordset is Set in the calling form.
GOT IT! Run didn't like the syntax
Code:Forms!frmRegistry.rsRegEMAs.RecordCount
Last edited by GraeagleBill; 05-17-2021 at 04:33 PM.
Personally, anything I want to be able to reference from different forms is declared in a standard module. Generally all in the same one too, much the same as most of us put all our variable declarations at the top of a procedure, not sprinkled throughout. That's just a style thing though.
By the way, as you haven't given us the context with which you're using this, I'll throw out another option. You could have a function that contained the recordset and it returns the count. It could take any parameters required by the recordset.
The context is, I thought a simple one, one form sets and loads the records into a "public" DOA Recordset and a second form under optional circumstances processes the contents of the Recordset. I just want the first form to be able to "share" the Recordset with the second form. Why having made the Recordset Public didn't get the job done is still a mystery to me.
It's because when you set a declare Public Variable in the forms module, it is still only available in that form (It is still a form variable in it's scope).
Any code in that form will be able to use it but nothing outside of the forms scope will see it.
More and better words here https://bytes.com/topic/access/insig...-vba-ms-access
DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
Please use the star below the post to say thanks if we have helped !
↓↓ It's down here ↓↓
Thanks Minty, that clears up that question. My normal practice is to declare variables at the beginning of a form's module when I need all the module's subs/functions to have shared access. When I need global sharing, such declarations go in a general module. Almost all my apps have a ModGlobalVars where such declarations appear. With the current situation, there's no need to share the DOA Recordset across the whole app, just between two foms that have related functionality.
The current reference: With Forms!frmRegistry.rsRegEMAs. is getting the job done so I'll just stick with that.