This article was previously published under Q207860
For a Microsoft Access 97 version of this article,
see
162660�
(http://support.microsoft.com/kb/162660/
)
.
Advanced: Requires expert coding, interoperability, and multiuser
skills.
This article applies to a Microsoft Access database (.mdb) and to a
Microsoft Access project (.adp).
For a Microsoft Access 97 version of this article,
see
162660�
(http://support.microsoft.com/kb/162660/
)
.
↑ Back to the top
If you call a procedure in a form class module from the OnAction property of a command bar control, the function runs three times.
↑ Back to the top
Store the procedure in a standard module instead of in the
class module of a form. When you call a procedure in a standard module in the OnAction property of a command bar control, the procedure runs only once.
↑ Back to the top
Steps to Reproduce Behavior
- Start Microsoft Access, and then create a blank Access
database named Dbtest.mdb.
- In the Database window, under Objects, click Forms, and then click New. In the New Form dialog box, click Design View, and then click OK.
- On the View menu, click Code.
- In the Class Module sheet, type the following procedure:
Function CmdBarTest()
MsgBox "Running CmdBarTest()"
End Function
- On the File menu, click Close and Return to Microsoft
Access.
- On the View menu, click Form View.
- On the View menu, point to Toolbars, and then click Customize.
- In the Customize dialog box, click the Toolbars tab, click New, and then name the toolbar ToolbarTest. Click OK.
- Click the Commands tab in the Customize dialog box, and then select Toolbox in the Categories box.
- Drag the command button from the Commands box to your empty ToolbarTest toolbar.
NOTE: The toolbar may show only the first one or two letters of its
name. - Click Modify Selection in the Customize dialog box, and then click Properties.
- Type the following line in the On Action box:
=Forms!Form1.CmdBarTest
- Click Close in the Control Properties dialog box, and then click Close in the Customize dialog box.
- With the form open, click the command button on the ToolbarTest toolbar. Note that you receive the "Running CmdBarTest()" message
three times.
↑ Back to the top
For more information about adding custom buttons to a
toolbar, click Microsoft Access Help on the Help menu, type add a button to a toolbar in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
↑ Back to the top