Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Function called from command bar control runs three times in Access


View products that this article applies to.

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


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.

↑ Back to the top


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.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in Access.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Keywords: kbpending, kbbug, kbfunctions, kbprogramming, kbusage, KB207860

↑ Back to the top

Article Info
Article ID : 207860
Revision : 7
Created on : 7/28/2006
Published on : 7/28/2006
Exists online : False
Views : 480