Global Variables Reset on Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Xanfere
    New Member
    • Dec 2008
    • 2

    Global Variables Reset on Error

    Hello All,

    I have an issue with an Access 2003 ADP file hooking up to SQL Server 2005.

    I had a global variable in a module like the following:

    Public loginUserName As String

    I found out that upon errors, the value for this variable gets reset. So, after some initial online research, I changed this variable to a property in a code module:

    Public Property Let UserID(strUID As String)
    mstrUID = strUID
    End Property

    Public Property Get UserID() As String
    UserID = mstrUID
    End Property

    That seemed to work initially when combined with a generic error handler that is used to log all errors.

    I've just recently been notified by the Client that the value from "UserID" is still getting flushed out -- but mainly on "timeout expired" errors.

    Is there a way (with fewer resources used as possible) to maintain these "global" values upon errors/timeouts?

    Thanks!!
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, Xanfere.

    To the best of my knowledge, when error has been handled and cleared via some kind of Resume statement, global variable are not destroyed.

    Regards,
    Fish.

    Comment

    • Xanfere
      New Member
      • Dec 2008
      • 2

      #3
      I did a workaround...

      Upon successfully logging into the app, I write the values to a text file (in the same folder as the .adp file). Then, if any of these values are blank when I access it, I just read in the values from the text file and refresh the custom properties.

      So far, it seems to work fine...

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        You could also store the values not visible on a form or on a hidden form, or just call the function to get the user name anew any time you need it and it's blank, rather than use the text file.

        Comment

        Working...