In Microsoft Access 2000, you can use the Toolbar Control Properties dialog box for command bar controls to set the OnAction property for a control on a command bar. Display the Customize dialog box by pointing to Toolbars on the View menu and clicking Customize. For menu bar and toolbar controls, display the menu bar or toolbar, and then right-click the control whose OnAction property you want to set. For shortcut menu controls, select the Shortcut Menus check box on the Toolbars tab of the Customize dialog box, then find the shortcut menu control you want on the menu bar that's displayed and right-click the control. Click the Properties command. Enter the macro or Sub procedure you want to run in the On Action box.
You can use the OnAction property only to run a macro or a Sub procedure. To run a macro, select it from the drop-down list in the On Action box, or enter its name in the box. To run a Sub procedure, enter its name in the form =subname( ) in the box.
You can also set the OnAction property to an expression. The expression can contain a built-in or user-defined Sub procedure or combination of Sub procedures. When Microsoft Access evaluates an expression, it performs all of the operations in the expression. For example, the following is an expression that runs the user-defined Sub procedure "CustomControlProc":
=CustomControlProc()
In Visual Basic, the OnAction property takes a string, so to set it to an expression, you must pass it a string that contains the expression. In passing the string, be careful to enclose strings within the string in quotation marks ("). (Note that in the On Action box in the Toolbar Control Properties dialog box, an enclosed string in the expression should only have one set of quotation marks around it.) Also, make sure you include the equal sign (=) to specify that the string contains an expression. Your Sub procedure must contain no arguments, remember to include parentheses [( )] within the string. You can set the OnAction property to the previous expression with the following string:
"=CustomControlProc()"
Note that you must set the OnAction property to the name of a macro or Sub procedure; you can't set it to the name of a Function procedure.
For custom command bar controls, you must set this property in order for the control to perform any action. If you set this property for a built-in control, the OnAction property setting overrides the normal actions that the control performs; that is, you can force a built-in control to perform different actions from its default actions. The control becomes in effect a custom control.