Access.2007.VBA.Bibl..

(John Hannent) #1
FIGURE 13.5

References set to the Access and DAO object libraries in the VB References dialog.


You can now modify the form (if you need a form in your add-in), and the code in the standard
module and designer, to create a custom COM add-in for use in Access:


  1. First open the designer and fill in the basic information about the add-in on its General
    tab (the Advanced tab rarely needs to be modified from its default settings).

  2. Enter the add-in’s display name and description in the “Addin Display Name” and “Addin
    Description” boxes, then select the Office application (Access in this case) from the
    Application drop-down list (see Figure 13.6). The currently running Office version is
    automatically selected in the Application Version box.

  3. Finally, select the add-in’s load behavior from the “Initial Load Behavior” drop-down —
    Startup is the appropriate choice if you want the add-in to always be available in any
    Access database (which is the usual case).


The SharedCode module (as its name suggests) contains code that applies to the entire add-in,
such as an error handler and the standard code that creates and removes the add-in’s toolbar but-
tons or menu items (for the rare case where a multi-application COM add-in puts a command on
the same menu or toolbar in each Office application).

The code in the Designer (which I named AccessDesigner to indicate that it is an Access Designer)
contains code specific to Access. (If you are creating a multi-application add-in, you need to create
one Designer for each Office application that your add-in supports). Some of the standard code in
the Designer works with the frmCOMAddIn form; if your add-in doesn’t need to display a form,
you can delete or comment out any code that references this form, but it is a good idea to leave all
the procedures in the module, in case you might need them later on.

Creating COM Add-ins with Visual Basic 6 13

Free download pdf