O'Reilly logo

Beginning Access™ 2007 VBA by Denise Gosnell

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

11.4. Libraries

So far, all the code you have written works only from within the database where you created it. There may be times when you want to reuse code across multiple Access projects, such as when performing a common task that multiple databases might need to perform. You can create libraries based on a specific Access databases that can then be referenced from and used by other Access databases. However, in order to be a good candidate for a library, the database should contain only generic procedures and functions, and not specific references to forms or other objects that may not be present in the other applications or databases from which the library might be used.

Try It Out: Creating and Using a Code Library

In this example, you will create a new Access database containing a sample error-handling procedure that you will make available to other Access databases. This error-handling procedure was described in Chapter 2. You will add the new database as a Library and then use the Library from another database.

  1. Create another new database, by selecting the Office Button New. From the list of available templates, select "Blank Database." Name the new database ErrorHandlerLibrary and click the Create button.

  2. Insert a new module into the ErrorHandlerLibrary database. Name the module modError.

  3. Add the following procedure to the new modError module:

    Public Sub GeneralErrorHandler(lngErrNumber ...

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