ACC: ShowToolbar May Not Show Library Database Custom Toolbars

ID: Q153673


The information in this article applies to:
  • Microsoft Access versions 7.0, 97


SYMPTOMS

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

The ShowToolbar action does not show custom toolbars that are stored in library databases, unless the library database is loaded as an add-in.


CAUSE

Microsoft Access version 2.0 and Microsoft Access version 7.0 or later differ in the way they load library databases. For performance reasons, Microsoft Access 7.0 or later does not load a library database into memory until code in an active application calls that library. Code in the library database can open objects, such as forms and reports, but the ShowToolbar action will not show or hide a toolbar unless the library database was loaded as an add-in.


RESOLUTION

The following example creates a database that can be loaded with the Add-in Manager:

  1. Create a new database called Toolbars. Save it as type Add-ins (*.mda).


  2. If the system tables are not displayed, on the Tools menu, click Options. On the View tab, click to select System Objects, and then click OK.


  3. On the File menu, click Database Properties. In the Properties dialog box, click the Summary tab, and then type Custom Toolbars in the Title box. Click OK.


  4. Create a new table called UsysRegInfo with the following structure:
    
           Table: UsysRegInfo
           ----------------------------
           Field Name: Subkey
              Data Type: Text
              Field Size: 255
           Field Name: Type
              Data Type: Number
              Field Size: Long Integer
           Field Name: ValName
              Data Type:  Text
              Field Size: 255
           Field Name: Value
              Data Type: Text
              Field Size: 255 


  5. Enter three records into the UsysRegInfo table. The Subkey for all three records should be:
    
           HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\Custom Toolbars 

    The values in the other fields for each record should be as follows:
    
           Subkey         Type           ValName          Value
           -----------    ----           -------          -----
           (see above)    0
           (see above)    1              Expression       =LoadToolbars()
           (see above)    1              Library |ACCDIR\Toolbars.mda 


  6. On the View menu, click Toolbars. In the Toolbars dialog box, click New. In the New Toolbar dialog box, type "NewBar" (without the quotation marks), and then click OK. Note that a new, blank Toolbar appears. Click Customize, and drag a few buttons to the new, blank Toolbar. Close the Customize Toolbars dialog box.


  7. Create a new module with the following function:
    
           Function LoadToolbars()
              DoCmd.ShowToolbar "NewBar"
           End Function 


  8. Compile and save this module.


  9. Close Toolbars.mda.


  10. Open the sample database Northwind.mdb.


  11. On the Tools menu, point to Add-ins, and then click Add-in Manager. A list of available Add-ins will appear. "Custom Toolbars" will be in the list if Toolbars.mda was saved in the Access directory. If it is not in the list, click Add New, find and select Toolbars.mda, and then click OK. Select "Custom Toolbars," and click OK. An X should appear to the left of the library database in the Add-in Manager dialog box, indicating that it has been installed.


  12. Close the Add-in Manager.


  13. On the Tools menu, point to Add-ins. Custom Toolbars should now appear in the list of add-ins. Click Custom Toolbars. The new toolbar, NewBar, should appear.



MORE INFORMATION

Steps to Reproduce Behavior


  1. Create a new database called Toolbars.mda.


  2. On the View menu, click Toolbars. Click New. Create a new toolbar and call it NewBar. Click Customize. Drag a few buttons to the new toolbar. Close the Customize Toolbars window.


  3. Create a new module with the following function:
    
          Function LoadToolbars()
             docmd.ShowToolBar "NewBar"
          End Function 


  4. Close Toolbars.mda.


  5. Open the sample database Northwind.mdb.


  6. Click the Modules tab and open the Utility Functions module in Design view. On the Tools menu, click References. In the References dialog box, click the Browse button, find, and click to select Toolbars.mda. Once it is added to the available references list, click OK.


  7. Press CTRL+G to open up the Debug window.


  8. In the Debug window, type the following line, and then press ENTER:
    ?LoadToolbars()

    Note that you receive the following error message:
    Run-time error '2094':
    Microsoft Access can't find the toolbar 'NewBar.'


NOTE: An easy way to make custom toolbars available to all databases is to use the built-in Utility1 and Utility2 toolbars. In addition, custom toolbars in other Microsoft Access databases can be imported into the current database.


REFERENCES

"Building Applications with Microsoft Access for Windows 95", Chapter 12, "Using Library Databases and Dynamic-Link Libraries", page 295, and Chapter 16, "Creating Wizards, Builders, and Add-ins", pages 359-375

For more information about creating and testing Add-ins, please see the following article in the Microsoft Knowledge Base:

Q143270 ACC95: Creating and Testing Add-ins Paper Available in Download Center

For more information about the UsysRegInfo table, search on "USysRegInfo" using the Microsoft Access for Windows 95 Help Index.

For more information about using Utility Toolbars, search on "Utility Toolbars," using the Microsoft Access for Windows 95 Help Index.

Additional query words: Run-time add-in

Keywords : kberrmsg kbusage GnlApp
Version : 7.0, 97
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.