TempVar Object and TempVars collections enable developers to manage and exchange data between macros and VBA procedures. There are several factors to remember when working with a TempVar. First, a TempVar is created by using the Add method or the SetTempVar macro action. Second, once created, a TempVar object remains in memory until Access is closed, so it is a good practice to delete it after it has served its purpose. Take a minute to think about this and you'll recognize a tremendous benefit. This means that the TempVar can store a global variable and it will not lose its value if there is an error.
Third, you can delete one TempVar with the Remove method or the RemoveTempVar macro action or you can delete all TempVars with the RemoveAll method or the RemoveAllTempVar macro action. Either approach deletes the specified objects from the TempVars collection. Fourth, the TempVars collection has a limit of 255 TempVars. And finally, a TempVar can be referred to by its ordinal number or by its Name as specified in the property setting.
You spent some time with macros in Chapter 2 and you'll work with them again in the chapters on forms and reports.
Was this article helpful?