Public Variables Persistence

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sedrick
    New Member
    • Aug 2011
    • 43

    Public Variables Persistence

    Hi,

    I created some Public variables using Access 97 to hold often used database options.

    One example is a variable to test for debugging mode, so the code can make special considerations for printing debugging code, etc.

    The variables are set in the top of a module, before any Procedures with this kind of syntax:

    Code:
    Public bDBUGGING as Boolean

    In Access 97 it works fine. The value stays in the public variable in between actual testing runs, while I am coding, etc. Then when code is ran it finds the values previously set, either by hand or in VBA code.

    When I try to use this in Access 2003 however, it acts different. It holds the value while the code is executing but then loses the value when execution finishes.

    Is there any way in 2003 to configure the database to keep the value between code runs? For example, when you are just sitting at a menu, the VBA is not executing, and then you click a button that uses the this value.
  • Sedrick
    New Member
    • Aug 2011
    • 43

    #2
    Thanks for looking.

    I think I found the problem.

    I had an error going on with some assignments to a Collection. For some reason it seemed to assign all the properties of a form to it instead of the string. When I cleared that up, the other problem with the public variables holding their values cleared up!

    I also recalled that a Public variable will lose its value under some error conditions.

    (By the way, the workaround to the collections assignment problem seemed to be related to variable types. When reading values from a table and assigning them or when trying to add a collection member of type Variant. I solved it with a work-around that explicitly converts the variable type before assigning the value to the collection.)

    Thanks again!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      FYI: Any time your code is reset, which happens automatically after a crash unless the debug option is avaialable and chosen, all public variables are, of necessity, reset. All values are therefore lost at this point, clearly.

      Comment

      Working...