Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228

    Unhappy Unanswered: problems with module global variables

    I am having problems accessing module global variables in forms. The value of them is set in the OnLoad event procedure. On some occasions I can't track down they get reset to their uninitialized state. Usually but not limited to right or shortly after opening the form. This is extremely hard to reproduce and more likely to occour early after the start of Access. It is not dependent on any data displayed or even specific forms although more complex forms appear to be affected more likely. I suspect dependency on system load, maybe a race condition. It doesn't seem to appear when stepping through the debugger.
    It is usually not that huge of an issue for me as the values are merely cached values and the unitialized state is not within the valid data range of my cached data most of the time. So I can work around the problem by merely retrieving the value again. Nonetheless it's a major annoyance and causes lots of unneccessary lines of code.

    Simplified example code:
    Code:
    Private QueryDelay As Long 'module global variable
    
    Private Sub Form_Load()
    QueryDelay = GetSetting("fArtikel.QueryDelay") 'GetSetting runs a query to retrieve the value
    Assert "Form_fArtikel", "Form_Load()", "QueryDelay > 0", QueryDelay > 0 'This assertion never fails!
    End Sub
    
    Private Sub Form_Current()
    Assert "Form_fArtikel", "Form_Current()", "QueryDelay > 0", QueryDelay > 0 'this assertion fails when the error occours
    Me.TimerInterval = QueryDelay
    End Sub
    
    Private Sub Form_Timer()
    Me.TimerInterval = 0 'reset timer to avoid running queries twice
    'run some more complex queries
    End Sub
    The idea here is to avoid blocking Access OnCurrent to run the more complex queries. Only if the user remains on a record for QueryDelay or longer they are executed (much like function calls in fields). Note that OnCurrent is after OnLoad in the event chain.

    It has been reproduced on Access 2000 (9.0.6926 SP-3 and earlier) on different platfowms (Win2k SP4 and earlier, Win98) on about 50 different machines (my Assert logs to a database). Tables are included via ODBC and additional queries run via ADODB. The problem has plagued me for months now and I'm still quite clueless what the problem is. Has anyone seen similiar effects or can point me to some information?

    With kind regards
    Michael Apel

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    globals can evaporate when there in an error event. mostly my progs die completely when a global dies 'cos i use lots of them.

    an idea i haven't tried yet is to have a "monitor" global
    global EverythingIsStillOK as bool

    set
    EverythingIsStillOK = true
    when you initialise your globals

    and then before using your globals...
    if EverythingIsStillOK then
    'do whatever you want
    else
    'recreate your globals
    endif


    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    at least I'm not alone

    I observed the error case as well, this happens without any visible error condition though. Your workaround is nicer as mine as you can always detect the bustage
    Any clue from M$ about the issue?

    Michael

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i use a lot of
    docmd.runsql
    and if i don't turn warnings off the user gets a chance to cancel and i have seen this kill globals sometimes (but (confusingly!!!) not always).

    for progs that "must not crash" i use error trapping even if it is nothing more than the totally stupid:
    on error goto err_myroutine
    exit_myRoutine:
    exit sub
    /func
    err_myRoutine:
    msgbox err.descr, vbcr, "ERROR: " & err.nu
    resume exit_myRoutine:

    in any routine that has even 0.0001% chance of error and (so far) i have never lost a global in these "mission-critical" progs

    i have not personally seen globals evaporate without an error (which is why i have not yet experimented with the EverythingIsStillOK idea), and "stupid" error trapping seems to be enough to preserve the globals.

    if you are losing your globals, i suspect there is an untrapped error somewhere that is causing the prob.

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    Yea, I have error trapping basically everywhere, not only 'cause of the global vanishing thingy but also users tend to panik when seeing a debug window.
    I don't use RunSQL, mostly ADODB.Execute and I'm sure it's not an ctrl+pause thing going on. Besides I do encounter the problem myself at times and I am absolutely sure it's not an error, not even a trapped one. Only thing I could imagine would be a silent error in one of the API calls, will check on them.

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    never mind the users, i panic if they see the debug window!

    good luck with the research - don't forget to post here if you find the answer.

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    OK, here's some more info. There are no errors in any of the API calls either but I found something interesting. The error appears with quite high probability the second time Form_Current is processed (but not the first) after system (re)start, after that it won't really appear again. Restarting Access does not make a difference. Appears to be some dll/ole/activex/whatever f*ckup. Still needs further investigation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •