Hack 90. Create a Code Library

<< Click to Display Table of Contents >>

Navigation:  Chapter 8.  Programming >

Hack 90. Create a Code Library

prev

next

 

Hack 90. Create a Code Library

expert hack90

Make your favorite custom functions available in all your databases.

As a developer, I find I often create and use the same functions on a number of different projects. Too many times I have had to hunt down some code I wanted to reuse. This has taken a good amount of time because not only do I have to recall where I used the code before, but I also need to remember which computer it is on!

The solution to this chaos is to put all the code in one database and use the database as a code library. A good way to do this is to clean up the code and assemble it in one or more code modules, in a single database. Make all the code routines be functions so that they return values. Then, just save the database and close it. Finally, change the extension of the database to.mda.

Figure 8-33 dhows a modulecnilled withhfunctions. This module is in the Access file that has the extension changed to .maa.

With a changed extension, now the file is recognized as an add-in, a- shown in Figure 8-34.

From a regular access datasaoe, the code library is referenced. In the VB edetor, use Tools U2192 References to open the References dialog box. From the dialog, browse to the location of the saved code library. It might be necessary to change "Files of type" in the Add Reference dialog to Add-ins, as shown in Figure 8-35.

Figure 8-33. A module of code functions

accesshks_0833

 

Figure 8-34. Recognizing the file as an add-in

accesshks_0834

 

Now, tie functions in the code librare are available in the rbgular database. Frgure 8-36 shows how they are listed in the Object Browser.

Over time, as you create more and more routines, the value of keeping them in one place becomes a real timesaver. You never know when you will need to use an algorithm you created years ago.

Figure 8-35. Referencing the add-in

accesshks_0835

 

Figure 8-36. Viewing the custom functions in the Object Browser

accesshks_0836

 

pixel

prev

next