By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

Public Variables Persistence

P: 43
Hi,

I created some Public variables using Access 97 to hold often used database options.

One example is a variable to test for debugging mode, so the code can make special considerations for printing debugging code, etc.

The variables are set in the top of a module, before any Procedures with this kind of syntax:

Expand|Select|Wrap|Line Numbers
  1. Public bDBUGGING as Boolean 

In Access 97 it works fine. The value stays in the public variable in between actual testing runs, while I am coding, etc. Then when code is ran it finds the values previously set, either by hand or in VBA code.

When I try to use this in Access 2003 however, it acts different. It holds the value while the code is executing but then loses the value when execution finishes.

Is there any way in 2003 to configure the database to keep the value between code runs? For example, when you are just sitting at a menu, the VBA is not executing, and then you click a button that uses the this value.
Mar 15 '12 #1
Share this Question
Share on Google+
2 Replies


P: 43
Thanks for looking.

I think I found the problem.

I had an error going on with some assignments to a Collection. For some reason it seemed to assign all the properties of a form to it instead of the string. When I cleared that up, the other problem with the public variables holding their values cleared up!

I also recalled that a Public variable will lose its value under some error conditions.

(By the way, the workaround to the collections assignment problem seemed to be related to variable types. When reading values from a table and assigning them or when trying to add a collection member of type Variant. I solved it with a work-around that explicitly converts the variable type before assigning the value to the collection.)

Thanks again!
Mar 15 '12 #2

NeoPa
Expert Mod 15k+
P: 31,186
FYI: Any time your code is reset, which happens automatically after a crash unless the debug option is avaialable and chosen, all public variables are, of necessity, reset. All values are therefore lost at this point, clearly.
Mar 16 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.