Microsoft KB Archive/207860

= Function called from command bar control runs three times in Access =

Article ID: 207860

Article Last Modified on 7/28/2006

-

APPLIES TO


 * Microsoft Office Access 2003
 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q207860





For a Microsoft Access 97 version of this article, see 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).



SYMPTOMS
If you call a procedure in a form class module from the OnAction property of a command bar control, the function runs three times.



RESOLUTION
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.



STATUS
Microsoft has confirmed that this is a problem in Access.



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.</li> On the View menu, click Form View.</li> On the View menu, point to Toolbars, and then click Customize.</li> In the Customize dialog box, click the Toolbars tab, click New, and then name the toolbar ToolbarTest. Click OK.</li> Click the Commands tab in the Customize dialog box, and then select Toolbox in the Categories box.</li> 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.</li> Click Modify Selection in the Customize dialog box, and then click Properties.</li> Type the following line in the On Action box:

=Forms!Form1.CmdBarTest

</li> Click Close in the Control Properties dialog box, and then click Close in the Customize dialog box.</li> With the form open, click the command button on the ToolbarTest toolbar. Note that you receive the "Running CmdBarTest" message three times.</li></ol>

<div class="references_section">