ACC95: How to Run a Function from a Custom Toolbar Button

Last reviewed: August 28, 1997
Article ID: Q137116
The information in this article applies to:
  • Microsoft Access version 7.0

IMPORTANT: This article contains information about editing the registry. Before you edit the registry, you should first make a backup copy of the registry files (System.dat and User.dat).

SUMMARY

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

This article describes how to run a Visual Basic for Applications function or expression from a button on a custom toolbar. The method involves three general steps:

  • Modifying the Windows 95 Registry to allow expressions in custom toolbars.
  • Creating a Visual Basic function.
  • Creating a custom toolbar button that calls the function.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access for Windows 95" manual.

MORE INFORMATION

Modifying the Windows 95 Registry

To modify the Windows 95 registry to allow expressions in custom toolbars, follow these steps.

For information about how to edit the registry, view the Changing Keys And Values online Help topic in Registry Editor (Regedit.exe). Note that you should make a backup copy of the registry files (System.dat and User.dat) before you edit the registry.

WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall Windows 95. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk.

  1. Start the Registry Editor. To do so, click the Start button, click Run, and then type "regedit" (without the quotation marks) in the Run dialog box. Click OK.

  2. In the Registry Editor dialog box, locate the following key:

          HKEY_CURRENT_USER
    

  3. Double-click HKEY_CURRENT_USER; double click Software; double-click Microsoft; double-click Access; double-click 7.0; and then select Settings. Using the right mouse button (right-click), click Settings, point to New on the menu that appears, and then click DWORD value on the menu that appears.

  4. Under Name, type the following name for the new DWORD value:

          ExprsInToolbars
    

  5. Select the "ExprsInToolbars" DWORD, and right-click the Modify command.

  6. In the Edit DWORD Value box, enter 1 as the value data, and then click OK.

  7. Close the Registry Editor.

Creating the Visual Basic Function

To create the Visual Basic function, follow these steps:

  1. Start Microsoft Access and open any database.

  2. Create a module and type the following line in Declarations section if it's not already there:

          Option Explicit
    

  3. Type the following procedure:

          Function Test()
    
             MsgBox "Hello!"
          End Function
    
    

  4. Close and save the new module.

Creating the Custom Toolbar Button

To create the custom toolbar button, follow these steps:

  1. In the Database window, right-click the toolbar and click Customize.

  2. In the Customize Toolbar box, scroll through the list of categories and select Expression.

    NOTE: If Expression does not appear in the list, please see the "Modifying the Windows Registry" section of this article for information on how to add this item to the list.

  3. Type the following expression in the Expression text box:

          Test()
    

    NOTE: Do not precede the expression with an equal sign (=).

  4. Drag the Expression text box to the toolbar.

    NOTE: The toolbar must be docked.

  5. If you want to change the button's icon, right-click the new button on the toolbar, and then click Choose Button Image. Select a different button, and then click OK.

  6. Close the Customize Toolbars box.

  7. Click the custom button on the toolbar. Note that you receive the "Hello!" message that you created in the Test() function.

REFERENCES

Microsoft Access "Building Applications with Microsoft Access for Windows 95," version 7.0, Chapter 1, "Creating an Application," pages 22-24

Keywords          : kbprg kbui PgmHowTo
Version           : 7.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.