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

    Global variable unavailable to sub-form


    I have a general module that Dim's a variable Global. I have a main form and several sub-forms. The main form sets the value of the global variable in its Open Event. However, when the sub-form(s) open the value of the global variable is zero. When I close the main form and then open it again the global variable has the correct value and all the sub-form(s) populate accordingly. What might be the best coarse of action to correct the situation?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Sub forms load before their master form loads so by the time you set the value of the variable in the main forms open event the sub forms open event has already happened.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Thanks Bob, that was my suspicion to begin with. Before I posted, I had tried to put a general module in "front" of the main form, set the variable and then open the main form. The problem there was that in my haste I failed to set Options to Explicit and the general module failed without notice leading me to believe that there were bigger problems with the global variable.

    The problem has been easily resolved by putting a small function in "front" of the main form, that is triggered by an Autoexec macro, that sets the global variable and opens the main form.

    Thanks again,
    Bill

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

Similar Threads

  1. Global variable for recordcount
    By Larryg in forum Forms
    Replies: 4
    Last Post: 03-19-2017, 04:31 PM
  2. Replies: 8
    Last Post: 10-08-2014, 06:08 PM
  3. Global Variable
    By gtg430i in forum Programming
    Replies: 11
    Last Post: 03-10-2014, 05:00 PM
  4. Can't See Global Variable
    By CementCarver in forum Programming
    Replies: 12
    Last Post: 09-19-2013, 12:28 PM
  5. Global variable
    By ramdandi in forum Queries
    Replies: 3
    Last Post: 12-18-2011, 01:01 AM

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