Module Variable Collapse

gray

Registered User.
Local time
Today, 14:37
Joined
Mar 19, 2007
Messages
578
Hi All

Access2002/2007
WinXPPro

I've found that sometimes, when an error occurs in my forms, the module variables (i.e. those declared at top of the form's module) can collapse.... this can happen even on fairly minor form errors but, of course, their collapse goes on to cause an even greater error... I eventually decided to replace my module variables with text and check boxes to hold their values but this caused form.dirty problems so I've gone back.

Shot in the dark, but is there any way of making these form module variables more sunstantive? I simply declare them at the moment as, for example, :

Public Allow_Save As Boolean

Thanks
 
First, I'm sure that if you find that you handle the error, the variables won't lose their values. They do values if you click "Stop" on the default VBA error dialog, but with an error handler, it doesn't happen. Hence the need to have error handler in at least every top-level procedure.

Second, some like to use a hidden form to hold the values. I'm not a big fan of that approach but that works for some. With 2007 or later, there's now a new "TempVars" collection which also persist even after an unhandled error.

Third, while that is not applicable for variables such as "Allow_Save", if you have object variables you want to refer at anytime without being concerned about what state it is in, take a look at Self-Healing Object Variables.

HTH.
 
Hi

I have error_handlers in all my procedures... but I'm thinking that maybe when I've called a 'in-module' procedure from. say, a button_click, and that 'in-module' procedure fails then somehow I'm not handling the fail as it gets passed back to the button-click event... I might elect to close the form on all failures since my forms all 'reset' themselves on load.

Thanks for the info about TempVars and Self-Healing... I shall investigate :) .... rgds
 
By all means lookup TempVars and Self-Healing but they will not fix the problem you should not be having.

If variables are being reset then they are being reset by the compiler; they are not simply evaporating into thin smoke.
If you don’t fix the problem, but simply apply another layer of obfuscation, then the problem will persist.
 

Users who are viewing this thread

Back
Top Bottom