Link to home
Start Free TrialLog in
Avatar of BD
BDFlag for United States of America

asked on

Defining new TempVars? Use ADD or DIM to establish TempVar?

Question about the better code to use for defining a new TempVar.  Use:

  1. TempVars.Add "NewTempVarsName", (set tempvars value)
  2. Dim NewTempVarsName As TempVar   ...then a few lines down...  TempVars!NewTempVarsName = (set tempvars value)

Is one method preferred over the other?  Advantages to either method?
Avatar of PatHartman
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I use them a lot, and prefer to initialize them in my startup or splash form, similar to the way that Pat does with her global variable form.  You can use syntax like:

Tempvars.Add strVarName, varValue


Tempvars!VarName = varValue

Either method works just fine.
Avatar of BD


Question to Pat:

First, thanks for the explanation on setting TempVars, good info.  

Second, using your hidden "global values" form, I assume you have a main form that is displayed when the database opens.  Do you use Form_Load to place your code for opening the hidden form and entering your initial values?  Could you provide an example of your code to do this?  Also, how are you hiding the form?

I am very weak with VBA and trying to learn.  Thanks.
TempVars are cool because they do not get hosed with a crash or when reset occurs, unlike Globals.
Also ... they can be called directly from Queries :-)

User generated image
Joe, I agree that TempVars are useful.  My point was that I solved the problem years ago and TempVars don't add anything to my existing solution and I think my existing solution is sufficiently good that it is worth a mention.  TempVars were implemented because of Webforms and Data Macros so if you are using them, TempVars is your only option.

BD,  I usually make my "hidden" form the form that opens when the database opens.  In the Current event, I set any defaults that need setting for the form's controls or TempVars if I've used them in this app.  Then I hide the current form by setting its visible property to False and open the Menu/Switchboard.  There is no logic involved.  It is simply a list of TempVars definitions followed by set statements if they variables need initiation.

Here's a picture of a hidden form from one of my apps.  As you can see, all the controls are unbound.  This particular app has no code in this form except to hide itself and open the switchboard since no TempVars were used and nothing required an initial value.User generated image
@Pat ... my post was unrelated to what you posted per se ... I simply commented and added my input on TempVars.
Not sure why ... you needed to address me in your last post ?