The procedures starting with Private Sub IDTExtensibility2are the events supported by
this library. You need to have all five event procedures in the Designer module, even though your
add-in may not use all of them. The ones I don’t need have only a comment line:
‘No code needed, but must have the event stub
COM add-ins generally put one or more buttons or commands on a toolbar or menu in the host
application; each one requires a WithEventsstatement in the Declarations section of the
Designer module, to support code on the Click event of the button or command. My LNC Control
Renaming code has two such events, to support two toolbar buttons.
The remainder of the Declarations section contains groups of public and private variables for use in
various add-in procedures. The procedures in this module have the functionality described next:
n The OnConnectionevent procedure sets the command bar button variables, and uses
the CreateFormCommandBarButtonand CreateReportCommandBarButton
functions to create the buttons on the Form Design (or Report Design) Access toolbars
(in older versions of Access), or in the Toolbar Commands group on the backward
compatibility Add-Ins tab of the Ribbon (in Access 2007 running on Windows XP).
n The OnDisconnectionevent procedure runs a function that removes the two com-
mand bar buttons when the add-in is disconnected by unloading the add-in from the
COM Add-Ins dialog (they are not removed when Access is closed).
n The two Click event procedures run the LNCRenameFormControlsand
LNCRenameReportControlsfunctions, which respectively rename form and
report controls.
An Access 2000–2003 command bar button has its OnActionproperty set to the name
of a macro (a Sub procedure with no arguments) that is run when the button is clicked;
the syntax is different for buttons placed on command bars from a COM add-in. Instead, the OnAction
property is set to the ProgId of the COM add-in, and the button’s Click event is handled by the Click
event procedure in the Designer module.
n The CreateFormCommandBarButtoncreates the Access toolbar button that renames
controls on open forms. The function first sets the pappAccessvariable to the
Access.Application object, then sets a reference to the Form Design toolbar (where the
button will be placed), looking for an existing button on this toolbar, using its Tag prop-
erty, and creating it if it does not already exist.
n The CreateReportCommandBarButtonprocedure does a similar job for the Report
Design toolbar button that renames report controls.
n The RemoveAddInCommandBarButtonfunction (called by the OnDisconnection
event procedure) removes the add-in’s command buttons.
n The LNCRenameFormControlsand LNCRenameReportControlsfunctions are
basically similar to the code in the Access LNC Rename add-in, so I will not discuss them
in detail. The main difference is that the COM add-in functions rename controls on the
open forms (or reports) only; the Rename Form Controls and Rename Report Controls
menu add-ins rename controls on all forms or reports, whether or not they are open.
NOTENOTE
Creating COM Add-ins with Visual Basic 6 13