ACC97: Function Called from Command Bar Control Executes 3 Times

ID: Q162660


The information in this article applies to:


SYMPTOMS

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

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.


MORE INFORMATION



Steps to Reproduce Behavior


  1. Open the sample database Northwind.mdb.


  2. Create a new form not based on any table or query in Design view called Form1.


  3. On the View menu, click Code.


  4. Type the following procedure:
    
          Function CmdBarTest()
             MsgBox "Running CmdBarTest()"
          End Function 


  5. Save Form1, and then open it in Form view.


  6. On the View menu, point to Toolbars, and then click Customize.


  7. In the Toolbars dialog box, click New, and then name the toolbar ToolbarTest. Click OK.


  8. Click the Commands tab in the Customize dialog box, and then select Toolbox in the Categories box.


  9. Drag the Command Button from the Commands box to your empty Toolbar.


  10. Click Modify Selection in the Customize dialog box, and then click Properties.


  11. Type the following in the OnAction property:
    =Forms!Form1.CmdBarTest


  12. Click Close in the Control Properties dialog box, and then click Close in the Customize dialog box.


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



REFERENCES

For more information about running a Visual Basic function from a button on a custom toolbar, search the Help Index for "toolbar buttons, adding to toolbars," or ask the Microsoft Access 97 Office Assistant.

Additional query words: menu command bar tool class


Keywords          : kbusage MdlProb 
Version           : 97
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: April 30, 1999