Microsoft KB Archive/162660

= ACC97: Function Called from Command Bar Control Executes 3 Times =

Article ID: 162660

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q162660



Advanced: Requires expert coding, interoperability, and multiuser skills.



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 a form's class module. 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 this to be a problem in Microsoft Access 97.



Steps to Reproduce Behavior
 Open the sample database Northwind.mdb. Create a new form not based on any table or query in Design view called Form1. On the View menu, click Code.  Type the following procedure:

Function CmdBarTest MsgBox "Running CmdBarTest" End Function  Save Form1, and then open it in Form view.</li> On the View menu, point to Toolbars, and then click Customize.</li> In the Toolbars dialog box, 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 Toolbar.</li> Click Modify Selection in the Customize dialog box, and then click Properties.</li> Type the following in the OnAction property:

=Forms!Form1.CmdBarTest

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

<div class="references_section">