Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Menu Option to Menu Bar 1

Status
Not open for further replies.
Jun 8, 1999
2
US
I have found how to add a menu option to the Main Menu bar in Access. But I am still having a couple of problems.<br>
<br>
1) It only allows me to run a macro, I cannot choose to run any other file.<br>
<br>
2) It only works in the database that I created it in. Eventhough the Menu Option appears in all databases that I open.<br>
<br>
What I am trying to do is this. We use Access as a front end to our company's database. I would like to create a help file that contains the data dictionary for our database and give the user a menu option that allows them to open the help file. Ideally it would be beside the current help option and would work much like Help.<br>
<br>
Is this possible in Access 97? I can get close but cannot get exactly what I want.
 
I may not answer your questions directly but...<br>
<br>
I have an application with similar requirements. I put my "help" information in a table. It contains a "topic" text field as primary key and a memo field for the text. Compose the text in a word processor & cut & paste into the table.<br>
<br>
The application has a main form that is opened at start-up. In the main form's load event I put a call to a routine that dynamically buids the menu bar option EACH time the form is loaded. I also delete the menu when the form is unloaded. <br>
<br>
The fact that menu items run macros is not a limitation. You can do virtualy anything from a macro. For example you can execute a code module from the macro that fires off another application... In the example below the Help option executes a macro that opens a form that displays the help topics. The form acts as a menu, when you click the topic the help text is displayed.<br>
<br>
The code to build the menu follows:<br>
<br>
Sub BuildBillingMenuControl()<br>
<br>
' Object variables...<br>
Dim cbc As CommandBarControl<br>
Dim cbPop As CommandBarPopup<br>
Dim cbPopBilling As CommandBarPopup<br>
Dim cbcAdmin As CommandBarPopup<br>
' Other...<br>
Const FORM_FACE As Integer = 1837<br>
Const TABLE_FACE As Integer = 1835<br>
<br>
' See the "Billing/Collection Menu" Help topic for an overview of how the menu items<br>
' are structured.<br>
<br>
' This routine builds the Billing/Collection menu item on the "Menu Bars" command bar.<br>
' The menu item is deleted and completely re-built each time the application executes.<br>
' This routine is called from the OnLoad event of the the Main Menu (frmMain).<br>
<br>
<br>
' Note: to get access to the command bar objects,<br>
' establish pointer to MS Office object library;<br>
' select Tool / References, check MS Office 8.0 obj lib.<br>
<br>
<br>
<br>
' Delete Billing/Collection menu item so it can be rebuilt<br>
<br>
Utility.DeleteBillingMenuControl<br>
<br>
' ===========================<br>
' Add Billing/Collection menu<br>
' ===========================<br>
<br>
Set cbPopBilling = CommandBars("Menu Bar").Controls.Add(msoControlPopup)<br>
<br>
With cbPopBilling<br>
.Caption = BILLING_BAR_CAPTION<br>
.BeginGroup = True<br>
End With<br>
<br>
' =========================================<br>
' Add menu items to Billing/Collection menu<br>
' =========================================<br>
<br>
' Note: The OnAction property contains the name of the macro to execute when<br>
' the menu item is clicked.<br>
' The FaceId property (optional) defines the button face or icon that you see<br>
' to the left of the menu item.<br>
' The two Help properties (optional) contain standard settings for this<br>
' type of control.<br>
' The BeginGroup property (optional) adds a line to the control to separate it<br>
' from the other contols.<br>
<br>
<br>
'Debug.Print "add Main Menu button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Main Menu"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormMain"<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add agt bal ledger button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Agent's Balances Ledger"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormAgtBalLed"<br>
.BeginGroup = True<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add loss susp ledger button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Loss Suspense Ledger"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormLossSuspLed"<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add PT ledger button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&PT Ledger"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormPTLed"<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add Pool Counter ledger button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "P&ool Counter Signature Ledger"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormPoolCounterLed"<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add Reports button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Reports"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormReports"<br>
.BeginGroup = True<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add Help button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Help"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormHelp"<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add Administration MENU item"<br>
Set cbcAdmin = cbPopBilling.Controls.Add(msoControlPopup)<br>
<br>
With cbcAdmin<br>
.Caption = "A&dministration"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
End With<br>
<br>
<br>
'Debug.Print "add acct code button to admin menu"<br>
Set cbc = cbcAdmin.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Account Codes"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenAccountCodeTable"<br>
.FaceId = TABLE_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add acct type button to admin menu"<br>
Set cbc = cbcAdmin.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "Account &Types"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenAccountTypeTable"<br>
.FaceId = TABLE_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add Location code button to admin menu"<br>
Set cbc = cbcAdmin.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Location Codes"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenLocTable"<br>
.FaceId = TABLE_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add loss code button to admin menu"<br>
Set cbc = cbcAdmin.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "Lo&ss Codes"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenLossTable"<br>
.FaceId = TABLE_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add SPEC code button to admin menu"<br>
Set cbc = cbcAdmin.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "S&PEC Codes"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenSpecTable"<br>
.FaceId = TABLE_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add Help button to admin menu"<br>
Set cbc = cbcAdmin.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Help Topics"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenHelp"<br>
.FaceId = TABLE_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add Report button to admin menu"<br>
Set cbc = cbcAdmin.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "&Report Menu Maint"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenFormReportMaint"<br>
.BeginGroup = True<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
'Debug.Print "add About button"<br>
Set cbc = cbPopBilling.Controls.Add(msoControlButton)<br>
<br>
With cbc<br>
.Caption = "A&bout Billing and Collection Ledgers"<br>
.HelpContextId = 120446977<br>
.HelpFile = "oftip8.hlp"<br>
.OnAction = "OpenAboutForm"<br>
.BeginGroup = True<br>
.FaceId = FORM_FACE<br>
End With<br>
<br>
<br>
<br>
<br>
' ============================<br>
' Release all object variables<br>
' ============================<br>
<br>
Set cbPop = Nothing<br>
Set cbPopBilling = Nothing<br>
Set cbc = Nothing<br>
Set cbcAdmin = Nothing<br>
<br>
End Sub<br>
<br>
<br>
<br>
<br>
The code to delete the menu is:<br>
<br>
Sub DeleteBillingMenuControl()<br>
Dim cb As CommandBar<br>
Dim cbc As CommandBarControl<br>
<br>
' turn off the Billing/Collection menu on the menu bar<br>
<br>
Set cb = CommandBars("Menu Bar")<br>
<br>
For Each cbc In cb.Controls<br>
If cbc.Caption = BILLING_BAR_CAPTION Then<br>
' Debug.Print cbc.Caption<br>
cbc.Delete<br>
End If<br>
Next cbc<br>
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top