Somos Expertos Access. Contacto atravez de Skype Skype logo expertos_7

Maximize the use of TempVars in Access 2007 and 2010

The TempVars collection has the ability to save developers time, improve the reliability of your programming and provide you with new ways to share information across your application.

TempVars were introduced starting in Access 2007 and represented a major addition to the arsenal of tools for professional developers. With it developers can now store their global variables in a stable environment that will retain values regardless of program crashes.

Before TempVars developers had limited choices when using application wide variables: module level variables; hidden forms or tables. Their are drawbacks to each approach, with module variables being the worst since they initialize if your program encounters an error; losing their assigned values in the process.

Use TempVars Everywhere
TempVars have no such limitation, they retain their values when your code encounters an error and can be used in Forms, Queries, Reports and code. You initialize them when your application starts and they disappear when your application terminates. In short, their a great way to share information across your program!

TempVars Collection
Add Method: Use it to add variables to the collection, all variables are of the variant type.

TempVars.Add Name, Value

Where Name is the name of your variable and Value is of course the value you wish to assign it. Some examples:
TempVars.Add “strAppName”, “Test Application”
TempVars.Add “lngClientID”, 123456789
TempVars.Add “bolLoginAgain”, True

Once assigned you can now use the value in your queries and code using the following methods:
TempVars!strAppName
TempVars.Item(“strAppName”)
TempVars.Item(0)
All three methods above would return “Test Application”.

Remove Method
Use this method to remove the variable or use RemoveAll to get rid of all of them.

Queries
One particular advantage of using TempVars is their availability in queries, which you can’t do with global variables without using a function. I created an entire multi-franchise database system using TempVars to differentiate between franchisee data, it made my life easier and improved the reliability of my application.

Conclusion
I encourage you to start using TempVars in your code and your queries in place of module variables or classes, providing your users with a better experience and making your code more powerful.

Acerca de

Juan Soto es un desarrollador senior de Access en IT Impact Inc. y un MVP de Microsoft Access y se especializa en Access con bases de datos de SQL Server. Su pasión por el acceso lo ha llevado ayudar a una amplia gama de empresas a establecer un entorno seguro, estable y eficiente con SQL Server. Él es un orador frecuente en los grupos de usuarios de Access en todo el país y recientemente habló en el Orange County SQL Saturday # 73. Si desea que Juan hable en su próxima reunión de grupo, puede ponerse en contacto con él aquí.

Publicado en Access Help, VBA

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

*

 

Quienes Somos

ExpertosMicrosoftAccess.com es un servicio de la empresa IT Impact, Inc., una compañía de programación y servicios para empresas en Latino América. Ofrecemos servicios en .Net, SQL Server y Microsoft Access. Muchos de nuestros desarrolladores han obtenido el galardón de Access MVP, un título proveído por Microsoft a aquellos que han hecho aportes a la comunidad y que han demostrado tener conocimientos superiores del producto.

Nuestro Equipo

  • Le ayudamos a "Descubrir el poder de sus datos™" con reportes y sistemas de Access excepcionales .
  • Creamos soluciones de bases de datos personalizadas utilizando Microsoft Access y / o SQL Server.
  • Nuestros consultores ganaron sus estrellas en las empresas de servicios y/o manufactura antes de convertirse en programadores.

Blogs anteriores