O'Reilly logo

Access 2003 VBA Programmer's Reference by Armen Stein, Graham Seach, Teresa Hennig, Patricia Cardoza

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.2. Using the Built-In VBA Registry Functions

Many programmers use global variables to hold values that are used throughout the application. There are two problems associated with this approach. First, if an unhandled error occurs, all your global variables are reset. Second, you have to reassign their values every time the application is launched. An alternative is to store this type of value in the database, but if you're storing the connection string to the remote data store, you might find it a little difficult to get at if your application doesn't know where to look.

Another alternative, one that is used in most professional applications, is to store such information in the Registry. You can store all sorts of information in the Registry, from simple values that your applications use from time to time, to connection strings, to user preferences, such as the position and color of forms, and so on.

VBA provides four native functions for manipulating the Registry within VB and VBA. The sole drawback to these functions (if you want to call it a drawback) is that they operate on only one part of the Registry; one that has been specifically allocated to VB and VBA.

The HKEY_CURRENT_USER\ Software\VB\ and VBA Program Settings key has been set aside for our exclusive use. As mentioned earlier in this chapter, this key is mirrored in HKEY_USERS\current user subkey\Software.

As application-specific Registry entries are stored using the application-name, section, key construct, it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required