Function called from command bar control runs three times in Access (207860)



The information in this article applies to:

  • Microsoft Office Access 2003
  • Microsoft Access 2000

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start Microsoft Access, and then create a blank Access database named Dbtest.mdb.
  2. 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.
  3. On the View menu, click Code.
  4. In the Class Module sheet, type the following procedure:
    Function CmdBarTest()
       MsgBox "Running CmdBarTest()"
    End Function
    					
  5. On the File menu, click Close and Return to Microsoft Access.
  6. On the View menu, click Form View.
  7. On the View menu, point to Toolbars, and then click Customize.
  8. In the Customize dialog box, click the Toolbars tab, click New, and then name the toolbar ToolbarTest. Click OK.
  9. Click the Commands tab in the Customize dialog box, and then select Toolbox in the Categories box.
  10. 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.
  11. Click Modify Selection in the Customize dialog box, and then click Properties.
  12. Type the following line in the On Action box:

    =Forms!Form1.CmdBarTest

  13. Click Close in the Control Properties dialog box, and then click Close in the Customize dialog box.
  14. With the form open, click the command button on the ToolbarTest toolbar. Note that you receive the "Running CmdBarTest()" message three times.

REFERENCES

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.

Modification Type:MinorLast Reviewed:7/28/2006
Keywords:kbProgramming kbfunctions kbbug kbpending kbusage KB207860 kbAudDeveloper