Solved Alternate way than global variables

PaquettePaul

Member
Local time
Today, 18:54
Joined
Mar 28, 2022
Messages
107
I have been using global variables and they worked in the spring but for some reason they are not working now. During my last visits here, people were talking about a different approach to declaring global variables but I can no longer remember what they were called. Please provide. Thanks
 
Perhaps TempVars.

Why would the globals no longer work - what changed?
 
There have been no changes to Access that would have "broken" global variables, so that change must represent some structural difference. The ways folks USUALLY accomplish data sharing across forms and/or reports is

a) global variables in a general module or a user-defined class - very large numbers of variables possible, no constraint on data type except possible size limits for the module as a whole.

b) a hidden form with unbound text-box controls - large number of variables but might be constrained as to number and type of values; cannot do the same thing with a report, though.

c) TempVars - up to 255 variables, each of which is named but must be a numeric type or text; cannot be objects or data structures

d) A named dictionary object - can store any object except an array

e) open a single-record recordset to be used for temp storage - up to 255 variables, cannot be objects or arrays, total characters in a record is constrained to 4K bytes, may have sharing constraints if multiple writers

There might be other ways to do this, but the above should cover most of the common ways.
 
Long before TempVars were introduced, I solved the "problem" by using a hidden form. The form was opened when the db opened and stayed open all the while the app was open. In apps that have a login form, that is the form I use for the "globals". This solved the problem of global variables losing their state under certain error conditions. the other useful feature of the hidden form was that I could unhide it during testing which made certain types of testing easier since I could just change the value and try a different logic path without going back to the beginning.

TempVars have some idiosyncrasies I don't like. For example, they force you to use the Value property of controls when you want to set the TempVar. I also don't like the fact that you can define them hither, thither, and yon which means it is hard to corral them for debugging. The hidden form means I don't lose sight of any "global" variable.

Keep in mind that most applications actually require very few global variables since most processing takes place within a form or within a report and if you want to call shared procedures stored in standard modules, you can always use arguments to pass in variables or even pass in a reference to the form object so the shared procedure can access form controls directly.
 
Btw, thanks for the responses.

I use global variables to:
- set up configuration fields that are loaded at app startup (e.g., federal tax rate)
- define generic varIables that have limited life and I do not want to define in each procedure such as gblErr, gblInt, gblTxt, gblKey
- sometimes to make limited key data available from a form to a report

i had my problem because I restarted a global variable setup procedure in a secondary form for test purpos3s and forgot to remove it. I have no idea why I seem to find the solution shortly after reporting it as a problem in the forum. Maybe something about writing it down and thinking about how others might pose questions as to the characteristics of the problem and solutions.

Pat, when I first started using Access, I used a hidden form. I then found out about global variables and have stuck with them since.
 
Btw, thanks for the responses.

I use global variables to:
- set up configuration fields that are loaded at app startup (e.g., federal tax rate)
- define generic varIables that have limited life and I do not want to define in each procedure such as gblErr, gblInt, gblTxt, gblKey
- sometimes to make limited key data available from a form to a report

i had my problem because I restarted a global variable setup procedure in a secondary form for test purpos3s and forgot to remove it. I have no idea why I seem to find the solution shortly after reporting it as a problem in the forum. Maybe something about writing it down and thinking about how others might pose questions as to the characteristics of the problem and solutions.

Pat, when I first started using Access, I used a hidden form. I then found out about global variables and have stuck with them since.
I expect thinking about it again did jog your memory.
fwiw, Tempvars weren't a think when I started, and I have never got in the habit of using them. In some ways, I appreciate losing the value of some variables because of an unhandled error, because if I used Tempvars, I might not even appreciate that I had an error at all.

Maybe you could add a "sentinel" variable to indicate that the public variables have been set, so you exit the sub if you try to call it a second time.
 
Pat, when I first started using Access, I used a hidden form. I then found out about global variables and have stuck with them since.
I made the hidden form to get around the problem with global variables:)
MS made TempVars to get around the problem with global variables:)
 

Users who are viewing this thread

Back
Top Bottom