Microsoft KB Archive/173796

= ODE97: Print Command Not Available in Run-Time Applications =

Article ID: 173796

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft Office 97 Developer Edition

-



This article was previously published under Q173796



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you build a custom menu bar in Microsoft Access 97 and include the built-in File menu, some commands do not appear on the menu in the run-time environment. For example, the Print command does not appear on the menu; as a result, you cannot modify the printer settings or properties.



CAUSE
Some menu commands, such as the Print command from the default File menu, are disabled in the run-time environment.



RESOLUTION
Use either of the following two methods.

Method 1: Use the Command Bar Wizard
You can use the Command Bar Wizard to replace the default menu bar with a custom menu bar. For more information about obtaining the Command Bar Wizard, please see the following article in the Microsoft Knowledge Base:

172300 ACC97: Command Bar Wizard Available in Download Center

Follow these steps to create a custom menu bar using the Command Bar Wizard:
 * 1) Open your database in Microsoft Access 97.
 * 2) On the Tools menu, point to Add-ins, and then click Command Bar Wizard.
 * 3) Under Select Type in the Command Bar Wizard dialog box, click New, and then click Next.
 * 4) In the Select Template list, click Database, and then click Next.
 * 5) Click Next, and then type a name for the menu in the Menu Name box.
 * 6) Click Build.

NOTE: The Command Bar Wizard will create a new menu and close any existing menus. You can dock the custom menu bar or move it to any location on the screen.
 * 1) On the Tools menu, click Startup.
 * 2) In the Startup dialog box, type or select your menu in the Menu Bar box.
 * 3) Click OK.

Note that the Print command is available when you open this database in the run-time environment, either by running a Microsoft Access application installed from disk images created with the Microsoft Office 97 Developer Edition or by running Microsoft Access using the /runtime switch. When you click Print, the Print dialog box appears.

Method 2: Call a Custom Print Function
You can create a Microsoft Visual Basic for Applications function that displays the Print dialog box and attach that function to a custom Menu Bar. To do so, follow these steps:

 Open your database in Microsoft Access 97. In the Database window, click the Modules tab, and then click New.  Type the following code in the module that you just created: Public Function PrintOut ' Attached to a custom Print command on a custom menu bar. ' Use the RunCommand method to display the print dialog box.

On Error GoTo ErrorTrap

DoCmd.RunCommand acCmdPrint Exit Function

ErrorTrap: ' Check whether the RunCommand method was canceled. ' If RunCommand is canceled, it generates a trappable ' run-time error (2501). If Err.Number = 2501 Then Exit Function Else MsgBox Err.Number & vbCRLF & Err.Description End If

End Function  On the Debug menu, click Compile Loaded Modules. Save the module as basPrintFunction.</ol>

Follow these steps to create the custom menu bar:


 * 1) On the View menu, point to Toolbars, and then click Customize.
 * 2) Click the Toolbars tab, and then click New.
 * 3) In the New Toolbar dialog box, type a name in the Toolbar name box, and then click OK.
 * 4) In the Customize dialog box, click Properties.
 * 5) In the Toolbar Properties dialog box, click Menu Bar in the Type list, and then click Close.
 * 6) In the Customize dialog box, click the Commands tab, and then click New Menu in the Categories list.
 * 7) Drag New Menu from the Commands box to your custom menu bar.
 * 8) On your custom menu bar, right-click New Menu and type a name for the menu in the Name box. Press ENTER.
 * 9) In the Customize dialog box, click File in the Categories box, and drag Custom from the Commands box to your new menu.

NOTE: When you drag the Custom command over the name of your new menu, it will create a blank menu. It is on this blank menu that you should place the Custom command.
 * 1) On your custom menu bar, right-click the Custom command from step 9 and type a command name, such as Print, in the Name box, and then click Properties.
 * 2) In the  Control Properties dialog box, type =PrintOut in the On Action box, and then click Close.
 * 3) Add any additional menu commands that you need in the same manner.
 * 4) In the Customize dialog box, click Close.
 * 5) On the Tools menu, click Startup.
 * 6) In the Startup dialog box, type or select your menu in the Menu Bar box.
 * 7) Click OK.

When you open your database in the run-time environment, either by running a Microsoft Access application installed from disk images created with the Microsoft Office 97 Developer Edition Tools or by running Microsoft Access using the /runtime switch, note that the Print command is now available. When you click Print, the Print dialog box appears.

<div class="moreinformation_section">

MORE INFORMATION
WARNING: The following steps change the StartUpMenuBar property of the Northwind sample database. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

Steps To Reproduce Behavior
<ol> Start Microsoft Access 97 and open the sample database Northwind.mdb.</li> On the View menu, point to Toolbars, and then click Customize.</li> In the Customize dialog box, click the Toolbars tab, and then click New.</li> In the New Toolbar dialog box, type a name in the Toolbar Name box, and then click OK.</li> In the Toolbars list, click the new toolbar, and then click Properties.</li> In the Toolbar Properties dialog box, click Menu Bar in the Type list, and then click Close.</li> In the Customize dialog box, click the Commands tab.</li> In the Categories list, click Built-in Menus.</li> Drag the File Menu from the Commands box, to the toolbar created in step 4.</li> In the Customize dialog box, click Close.</li> On the Tools menu, click Startup.</li> In the Startup dialog box, type or select your custom toolbar in the Menu Bar box, and then click OK.</li> Quit Microsoft Access and restart Northwind using the /runtime switch.

For example, click Start on the taskbar, and then click Run. In the Open box, type the following command on a single line:

"c:\Program Files\Microsoft Office\Office\msaccess.exe" "c:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb" /runtime

Note that the custom menu bar appears when Northwind opens, but it does not show the Print command.</li></ol>

<div class="references_section">