Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Apr 2002
    Posts
    75

    Unanswered: Global Variables

    Hello!

    I took over a big access 2002 application recently. There is a problem with global variables in this application. The first form (login) contains a procedure called Initialize() This procedure populates a number of global vars, such as g_rsErrors (tblErrors), g_rsStoreChange (tblChangeHistory), g_dbCurDB, g_UserID, g_UserName, etc. All these variables are used in standard modules in procedures that get values from the active form. The frmLoging stays open in the invisible mode through the whole application work cycle.

    When I just start the application, all vars get populated and work just fine, but after opening and closing various forms in the app, I start getting error #91 (Object variable is not set). I did step through the code and all these vars are "nothing". I wonder what happens... maybe the module that holds the variables gets unloaded somehow? How can I check if the module is still in memory? What else can cause this problem? I did check the code and didn't see anywhere these vars being set to "nothing" programmatically!

    Thank you,
    Vasilyok

  2. #2
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    It sounds like you are opening and closing forms yourself from the database window rather than having the app do the opening and closing of forms in the apps own way of doing it. If this is what you are doing, then when a form is closed before the app is ready for it to be closed, the object variable that was set somewhere could have gone out of scope. That is, whatever module that the variable was defined in was closed, then the variable has gone out of scope.

    Or am I assuming wrong, and you are just exercising the application the way a normal user would, and you are getting this error that way?

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    How are you declaring the variables and equallly importanyly - where?

    P.S. How are you nowadays Vic?
    George
    Home | Blog

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    do you get any other error before the #91 ?

    if you are running this as .MDB (yes - you are stepping thru code)
    AND the code uses error-driven stuff (e.g. check .MDE property and catch the error when in MDB or e.g. OnErrorResumeNext in an exit routine that tidies objects that may not exist)
    AND you have any setting other than BreakOnUnhandledErrors
    your runtime error will trash the global vars.

    try making MDE ---- do you get the same #91

    curiosity: if the values really are in a module, why is the login form kept open (invisible) once it has done the job of populating the glovars ?

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Apr 2002
    Posts
    75
    Thank you all for your replies!

    To GolferGuy:
    While testing I do open and close forms, but I do it in the way the users will be doing it. This is major data entry/data retrieval form, which is a third level in the so to say form hierarchy: 1st -- frmLogin, 2nd --frmMainMenu and 3rd --frmProjects. 1st remains open and invisible, 2nd-open and visible, 3rd-open or closed as needed. Multiple opening&closing of the 3rd forms causes that problem.

    To georgev:
    All global variables are declared in basGlobals and initialized behind frmLogin.

    To izyrider:
    I'll try playing with .MDE and see the outcome.
    To your "curiosity" question : I don't know --This is the way the author created the app. By the way, that was my initial concern -- there are so many modules in the application that get opened at the same time because procedures are not organized in a way that would help save memory resources; besides, forms that stay open are really big...Can it be that the modules are being overridden by other modules when there is no enough memory available?

    Thank you all again!!
    P.S. The application uses FMS libraries, just to let you know...Maybe there is something about these libraries that can be tied to the problem...

  6. #6
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    izyrider and vasilyok,

    Of course I don't know why this app has left the login form open, but hidden. But I have a form that I keep open, but hidden for the whole time the app is running. That is where I keep my global variables because queries can get the variables from this hidden form, but queries can not get them from a VB global variable, except by writting a function to get the variable into a query. You might want to check to see if any of the fields on that login form are being referenced by any queries, or anything else for that matter.

    georgev-
    I'm fine! Thanks for asking. When is your marriage planned for?

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    basGlobals is what, a class, a module, a form?!
    How are they declared, as in how have you "dimmed" them, per-se.
    Code:
    Public myVariable As String
    George
    Home | Blog

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by GolferGuy
    I'm fine! Thanks for asking. When is your marriage planned for?
    Glad to hear it Vic, don't see you around here as much anymore - I guess you're keeping yourself busy. I know it was ages ago now but how did that project we discussed turn out?

    And to answer your question: my fiancée has started her first year of a 3 year couse at Uni afer her gap year. Once she graduates we will begin planning things properly
    George
    Home | Blog

  9. #9
    Join Date
    Apr 2002
    Posts
    75
    GolferGuy,

    err.91 is returned for global rst-s and all these rst-s are declared in the module basGlobals. Should I transfer rst-s declaration to frmLogin instead? Thanks!

    georgev,
    all globals are declared in a module as follows:
    Public p_dbCurDB As Database
    Public p_strPath_FE As String
    Public p_rstErr As DAO.Recordset
    Public p_rstChanges As DAO.Recordset
    etc.
    Thanks!

  10. #10
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    With the global variables defined in a module, they should stay "in scope" until the database is closed. All modules are in scope while the database, therefore VBA project, is open. Class modules, which include Class Modules and form and report modules, are only "in scope" while they are in use, therefore for forms and reports, while they are open, but not while they are in design view.
    I'm at a loss, except for responding to an error with the End option as to why you would loose the variables.

  11. #11
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    So is it the recordsets that are nothing? What about the path variable is it Null?

    I have read that if you use DBEngine to open a database and then close the database object that any recordsets that were created using that database variable would also be closed. I just did a little test and I am not seeing that behavior, but maybe it applies depending on the scope of the variable.

    Not sure if this is relevant, but I would like to know if all of your variables are trashed or just the objects.

    Do you have Option Explicit set? Is it a typo?

  12. #12
    Join Date
    Apr 2002
    Posts
    75
    Only object variables are trashed--recordsets and dababase; the rest, such as UserID or path(string), work okay.

    Option explicit is set.

    Just a detail -- I don't close the database, it's closing frmProjects (while frmLogin and frmMainMenu stay open) causes problems with object variables.

    Thank you.

  13. #13
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Are your object variables defined in frmProjects or in a normal module, which I think you have said is named Declarations? Do you have any tools, like Speed Ferret (http://www.speedferret.com/). I have this one, love it!, and it will find EVERYWHERE a variable is used, including SQL that is created within VBA code. Just a thought.

  14. #14
    Join Date
    Apr 2002
    Posts
    75
    I've figured out that all global variables are being reset when an error occurs and I press OK on the msgbox with err.number and err.desc. By the way. I was wrong saying that only object var-s are being reset -- in fact all of the variables are trashed at that moment.

    My VBA is set to "Break on Unhandled Errors"

    Thanks!

  15. #15
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    pending questions:
    what happens in MDE ?
    do you get any error BEFORE the #91 throws ?

    izy
    currently using SS 2008R2

Posting Permissions

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