Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Passing a DOA Recordset to another form

    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

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    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.

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,522
    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.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    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:
    Code:
    Public rsRegEMAs As DAO.Recordset
    In called form:
    Code:
    MsgBox rsRegEMAs.RecordCount
    
    
    
    GOT IT!  Just had a syntax error
    
    Code:
    Forms!frmRegistry.rsRegEMAs.RecordCount
    MsgBox Forms("frmRegistry")!rsRegEMAs.RecordCount
    Neither 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)

    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.

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,522
    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.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,522
    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.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    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.

  8. #8
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    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 ↓↓

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing a recordset/array from one sub to another?
    By TerraEarth in forum Programming
    Replies: 5
    Last Post: 05-01-2018, 10:11 PM
  2. Replies: 17
    Last Post: 02-25-2018, 02:37 AM
  3. Replies: 5
    Last Post: 11-18-2016, 10:27 AM
  4. Replies: 11
    Last Post: 05-17-2013, 06:10 AM
  5. Replies: 2
    Last Post: 03-08-2012, 12:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums