Microsoft KB Archive/153673

= ACC: ShowToolbar May Not Show Library Database Custom Toolbars =

Article ID: 153673

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q153673



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:

 Create a new database called Toolbars. Save it as type Add-ins (*.mda). 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. 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.  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   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:

<pre class="fixed_text">      Subkey         Type           ValName          Value ---              ---          -       (see above)    0 (see above)   1              Expression       =LoadToolbars (see above)   1              Library |ACCDIR\Toolbars.mda </li> 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.</li>  Create a new module with the following function:

Function LoadToolbars DoCmd.ShowToolbar "NewBar" End Function </li> Compile and save this module.</li> Close Toolbars.mda.</li> Open the sample database Northwind.mdb.</li> 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.</li> Close the Add-in Manager.</li> 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.</li></ol>

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Create a new database called Toolbars.mda.</li> 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.</li>  Create a new module with the following function:

Function LoadToolbars docmd.ShowToolBar "NewBar" End Function </li> Close Toolbars.mda.</li> Open the sample database Northwind.mdb.</li> 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.</li> Press CTRL+G to open up the Debug window.</li> 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.'

</li></ol>

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.

<div class="references_section">