?
Solved

Global declaration string variables reset conditions?

Posted on 2012-09-18
6
Medium Priority
?
578 Views
Last Modified: 2012-09-24
I have a small VBA application that uses a global declaration module to hold string values for form names and report names. These are used to make the code more readable and maintainable but I am running into an issue outside of the development environment where these strings appear to reset spontaneously.

I was operating on the premise that global variable resets would only occur in these cases:

1 When the user presses End after a runtime error
2 When you click the stop button on the debugging toolbar
3 When you're in step mode and you close the VBE and click OK to stop debugging
4 When the code passes an End statement.

Unless the code is corrupted, none of these conditions should occur in production. All routines have error handlers and the VBA editor environment is not user accessible.

What other conditions may result in global variables being reset? At the time the error showed up the application was being used normally and did not experience any other preceding errors.
0
Comment
Question by:kkamm
  • 4
  • 2
6 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 38410248
Nothing.  You covered everything with #1 - 4 above.

<<Unless the code is corrupted, none of these conditions should occur in production. All routines have error handlers and the VBA editor environment is not user accessible.>>

 That is correct.

 Sounds like you have a bug that's causing the variables to be cleared.

Jim.
0
 
LVL 1

Author Comment

by:kkamm
ID: 38410660
Jim,

The globals are declared as constants and shouldn't be writeable at runtime.

Could this be a memory management issue? Does Access do any garbage collection that would affect globals over time? How about module headers? Is there anything that would cause a module to become inaccessible? I have 'Option Private Module' set on that particuliar module.

I will probably have to switch to either a hidden form or local table to store this stuff if the problem persists.
0
 
LVL 58
ID: 38410724
<<The globals are declared as constants and shouldn't be writeable at runtime. >>

 Then how are they getting cleared? Anytime the code is running, a constant will have a value.

 Does your code compile?

<<Could this be a memory management issue? >>

 No.

<<Does Access do any garbage collection that would affect globals over time?>>

 No. Globals remain in memory until the DB is closed.

<< How about module headers?>>

 No.  Standard modules once loaded are kept in memory until the DB is closed.

<< Is there anything that would cause a module to become inaccessible?>>

  You mean the constant?  No.  Only code execution stopping.

<< I have 'Option Private Module' set on that particuliar module.>>

  That won't have any bearing on this and it's not really needed.   Private modules only come into play with multiple VBA projects.

  Only thing that might be possible is some VBA project corruption, but if you had that, then I would think you would not see the constant at all.

  You might (after a backup) want to try a /decompile on it:

"C:\...\MSACCESS.EXE" /Decompile "C:\...\MyApp.MDB"

 After the DB opens, close it, re-open and do a compile.  You should have no errors.

<<I will probably have to switch to either a hidden form or local table to store this stuff if the problem persists. >>

 Yes, those are options but you should not be having a problem, especially with a constant.  There's not much that can go wrong there.

Jim.
0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
LVL 1

Author Comment

by:kkamm
ID: 38411393
Jim,

Thanks. i am going to try a fresh copy with a decompile and compact and repair pass, convert it to an MDE, and hope for the best.
0
 
LVL 1

Author Comment

by:kkamm
ID: 38429636
I cleaned up the executable and the error has not returned. I am going to assume it was an internal problem with that one file instance and not a coding issue.
0
 
LVL 1

Author Closing Comment

by:kkamm
ID: 38429643
The accepted answer was useful for confirming the assumptions I was operating with and allowed me to narrow down the source of the problem.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question