Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 36
  1. #16
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314

    I am sorry to be so dense. But do you have time to give me an example of how to use the variable in this instance?

  2. #17
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quick and dirty, but declare it at the top of the module so it's available anywhere in the form, set it in the load event and:

    Code:
            If Me.[ID] = 34 And lngID <> 34 Then    'SCATeam Ledger
                Me.CtrLedger.SourceObject = "Team Trans Subform"
                Debug.Print "setting for 34"
            ElseIf lngID = 34 Then    'Member Ledger
                Me.CtrLedger.SourceObject = "Team Mem_Ledgers Subform"
                Debug.Print "setting for all others"
            Else
                'not needed, here for the debug
                Debug.Print "not doing a thing"
            End If
            lngID = Me.ID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #18
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Second test might need to be

    ElseIf Me.[ID] <> 34 And lngID = 34 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #19
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Paul, the code, as written in Post 17 does not work. As modified in post 18, also does not work. In either case only the default SCATeam Ledger displays. However, the code as show below, does work. FYI: Until last week, I only had one Ledger form and it was and still is imbedded in the Ledgers Tab Container. It is now used as the SCATeam Ledger form. I suppose I can un-embed it from the contrainer, now that I am dynamically loading the two forms. Can you confirm that?
    Code:
            If Me.[ID] = 34 And LngID <> 34 Then 'SCATeam Ledger form
                 Me.CtrLedger.SourceObject = "Team Trans Subform"
                 Debug.Print "Setting for SCATeam Ledger form"
            Else
                'LngID = 34 Then 'Members Ledger form
                 Me.CtrLedger.SourceObject = "Team Mem_Ledgers Subform"
                 Debug.Print "Setting for Member Ledger form"
            'Else
                'Not needed.  Here for the Debug
                'Debug.Print "Not doing a thing"
            End If
            LngID = Me.[ID]
    Also, here is the Form Load property code placed at the top of the module. I wasn't sure if I should make it private or public, so I made it public. Perhaps you could clarify this point for me.
    Code:
    Public Sub Form_Load()
        Dim LngID As Long
        LngID = Me.[ID]
    End Sub

  5. #20
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Redundant, deleted

  6. #21
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Shouldn't hurt but there is no need for it to be Public.

    But if you want LngID to be available to multiple procedures it must be declared in the module header. So I don't see how your code can be fully functional.

    Do you have Option Explicit in the module header? It should be in every module. You can force this as a default in new modules with VBA Editor options setting:

    Tools > Options > Editor > require variable declaration
    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.

  7. #22
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Thanks for the clarification. I didn't know if a private variable was visible to the whole module.

    About Option Specific - Do I understand correctly that if Option Specific is not set, variables can be created on the fly, without first declaring them and they will still work? I guess that is why, when in the above code, earlier this morning, I misspelled LngID and it did not cause an error. The code didn't work correctly, until I corrected it, but Access didn't seem to care. I had wondered why it hadn't caused an error.

  8. #23
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    PMFJI

    Always use Option Explicit ---it will identify spelling errors and more, and save you from yourself and poorly executed good intentions.

    Good luck and Happy New Year.

  9. #24
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Agree and have a little info here:

    http://www.baldyweb.com/OptionExplicit.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #25
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Well, I do not see the Tools > Options to select. How do I get there?

  11. #26
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    On the VBA Editor window.
    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.

  12. #27
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    And by the way, the code I posted was working in the sample db, with the variable declared at the top of the module, not within a sub. That said, I was just judging by the debug results, I didn't bother trying to find which subform was changing.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #28
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    I would like to take this opportunity to thank you, Paul, June7, and Orange for your help over the last many months. It is greatly appreciated. You have made my project much better than it would have been otherwise. I have learned a lot, yet still, much more to learn. And My I wish you all a Happy New Year.

  14. #29
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad to help and happy new year!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #30
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    That is interesting. The declaration was in the On Load property, at the top of the module. I had it marked Public at the time. When I ran the debug, I saw it kept skipping the Member register. I checked the code over several times, but couldn't get it to work. At least it does seem to work properly with the simpler one "Else".

    Oh, I wonder if I had the LngID misspelled at the time. It may have been. I don't remember when I caught it. So that may have been the problem. It is funny how one sometimes just cannot see a misspelling.

    I now have the "Option Distinct" set.

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 01-18-2016, 07:02 PM
  2. Replies: 2
    Last Post: 01-14-2015, 12:00 PM
  3. Replies: 15
    Last Post: 04-17-2012, 01:42 PM
  4. Specific records in a form
    By ellixer in forum Forms
    Replies: 1
    Last Post: 06-30-2011, 08:56 AM
  5. Filter specific records on sub form
    By foxtet in forum Forms
    Replies: 5
    Last Post: 06-05-2011, 12:06 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