Continuation of Custom Menus and Toolbars - Access 2003.
Continued from earlier Post: Custom Menus and Toolbars
Open your database where we have created the Custom Menu Bar with the name MyMenuBar. Select Customize from the Toolbars sub-menu of the View Menu. Or you can right-click anywhere on the Menu Bar or Toolbar above and select Customize from the displayed Shortcut Menu.
You can also add built-in menu options directly from the Customize dialog, without copying or dragging them from existing menus, as we did in Step 11 of the earlier post. Click on the Commands tab in the Customize window. When you select a category from the list on the left, its corresponding built-in commands will appear in the list on the right. From there, you can simply click and drag any option onto your custom menu bar or toolbar—no need to press the Ctrl key. This makes it easy to organize frequently used built-in options for your users.
Custom Menu Options
12. Next, we’ll focus on creating completely independent menu options: Data Files, Process, and Reports. We’ll design custom programs or macros to define the actions for each of these menu items. Below is a sample image of the Data Files options I’ve added to the menu:
When you click on any option in the Data Files menu, it opens a corresponding form. To build these menu options, I’ve used three types of command items from the Menu Bar/Toolbar Customize dialog:
-
Custom – for a single menu item with text only,
-
New Menu – to create a submenu with a dropdown list, and
-
New – for button-style options, with or without an icon.
13. Select Files from the Categories list in the Customize dialog. Then, click and drag the Custom control from the Commands list and drop it into the Data Files menu’s dropdown area. Right-click on the newly added item, select Name, and type Address Book in the textbox.
NB: The name you enter in the Name: field is used to reference the menu item in your code, so it must not conflict with the name of any built-in menu. If a duplicate name is used, Microsoft Access will display a warning message. By default, the same text entered in the Name: field is also used as the menu caption (i.e., the label visible to the user).
For example, suppose we've named our menu item DataFile (without spaces) so it can be easily referenced in code. However, we want the user to see a more descriptive label, such as Add/Edit Data. To do this, right-click on the DataFile menu item, select Properties from the context menu, and enter Add/Edit Data in the Caption: box.
Repeat the process for the Department List option. The third item, 'Other Data', is a group item.
14. Scroll to the bottom of the Categories list and select New Menu. This will display the New Menu control in the Commands list. Click and drag it onto your menu, then rename it to Other Data. This sub-menu includes a drop-down area on the right, where we can add several New control buttons.
15. Click on the Files category in the Categories list (within the Customize dialog). The Custom and New options will appear in the Commands list. Click and drag the New button, drop it into the drop-down area of the Other Data sub-menu, and rename it to Staff List. Similarly, add another item and rename it to Branches in the Name field. Then, choose a button icon using the Change Button Image option.
16. Add three options to the Reports menu using the same steps as described earlier. Name the options as Address Labels, New Employees List, and Department Code List.
17. On the Process menu, add a single Custom control and name it Process Report. With that, our menu design is complete. All that remains is to define actions for each of the buttons.
The good news is that the hard part is behind you! It felt challenging only because this was your first time. Once you grasp the overall concept, you'll be able to build menus quickly and confidently. Moreover, if you design the menu with some level of standardization—keeping your future applications in mind—you can import this Menu Bar into new projects and easily customize it by redefining the associated actions.
Tip: You can redefine the Action of any built-in Menu Option as well.
Opening Data Files and Reports
We need two small programs to handle the Data Files and Reports menu options, along with a macro to execute the Process Report option. The VBA routines for the Data Files and Reports options are provided below:
Public Function DataFiles(ByVal intOption As Integer) Select Case intOption Case 1 DoCmd.OpenForm "Address Book", acNormal Case 2 DoCmd.OpenForm "Staff List", acNormal Case 3 DoCmd.OpenForm "Department List", acNormal End Select End Function
Before we begin assigning actions to the menu options, let’s understand how the above code works. When we call the DataFiles()
function, we must pass a numeric parameter corresponding to the position of the menu item. For example, if Address Book is the first item in the Data Files menu, we pass 1
as the parameter—like this: =DataFiles(1)
In the Action property of that menu option.
Inside the function, this value is evaluated using a Select Case
statement. Based on the case number (e.g., Case 1)
we define the specific action to take, such as opening a form. Similarly, the next item on the menu will be used 2
as its parameter, and so on.
Defining Actions for Menu Items.
18. Let’s define the action for the first button on the Data Files menu. If the Customize Toolbar control is not already visible, right-click on the toolbar area and select Customize.
Next, click on the Data Files menu to open the drop-down list. Right-click on the Address Book option and choose Properties. In the Action field, enter:
This tells Access to call the DataFiles()
function with the parameter 1
. Repeat this process for the remaining buttons, incrementing the parameter each time (2
, 3
, etc.). Make sure to keep track of the order, as this number will be evaluated in the code using a Select Case
block to determine which action to perform.
19. Follow the same procedure for assigning actions to the Reports menu options. In the Reports()
function (given below), notice that under the Case 2
statement, I’ve included a line to run a macro before opening the report in Print Preview mode.
This assumes that you've already organized a series of Action Queries within the macro to generate the data table required by the report. The macro is executed first to prepare the data, and only then is the report linked to the resulting table opened for preview.
Public Function Reports(ByVal intOption As Integer) Select Case intOption Case 1 DoCmd.OpenReport "Address_Labels", acViewPreview Case 2 If MsgBox("Re-process Report Data...?", vbYesNo +vbQuestion + vbDefaultButton2, "Reports()") = vbYes Then Docmd.RunMacro "ProcessData" End if DoCmd.OpenReport "New_Employees_List", acViewPreview Case 3 DoCmd.OpenReport "Dept_Codes", acViewPreview End Select End Function
We haven't forgotten our Process button in the middle. The word Process itself suggests that it involves multiple actions. Since the entire sequence is already handled within a macro, the action for this button is straightforward: just call the macro directly. There's no need to route it through a function or check option numbers. The output of the process—whether it's a message, a display, or a printout—can follow afterwards as needed.
20. Assume that we have created a macro named MyProcess and we want to link it to the Process Report menu option. To do this, display the Toolbars Customize control if it's not already open. Click on the Process menu, then right-click on the Process Report option and choose Properties. In the Action box, type MyProcess
.
=
sign—simply type the macro name.I don't prefer assigning a macro directly to a menu option. If the user accidentally clicks the button, the macro will execute immediately and run all the embedded Action Queries, potentially altering or recreating important data without confirmation.
A better and safer method is to pass control to a VBA program, as demonstrated in the Reports()
function under Case 2
. There, we first prompt the user to confirm whether they want to run the macro to recreate the Report Table. If the user selects No, the macro remains untouched, and the Report simply opens using the previously generated data.
This approach not only prevents unintended data manipulation but also provides the user with control over when to refresh the report data.
Although macros can be used to open Forms and Reports, they are not ideal in every scenario. If a user accidentally opens a Form or Report through a macro, it can be easily closed, so the risk is minimal. However, if you have multiple forms, assigning a separate macro to each one means you'll end up with a long, cluttered list of macros under the Macros tab in your database. This not only makes management more difficult but also reduces the overall maintainability of your application.
Toolbars & Shortcut Menus.
Now that you've mastered the art of creating Custom Menus, you'll find that building Toolbars or Shortcut Menus is no different. I won’t go on and on about it and risk boring you to death! Just know that you can easily organize your own Custom Toolbar—adding your personalized buttons along with frequently used built-in ones like Sort, Filter, Copy, Paste, and more. Define the actions as you did with the menu items, and you’ll have a streamlined interface tailored to your needs.
To create a custom Shortcut Menu Bar, start by creating a Custom Toolbar and setting its Type to Popup in the Toolbar Properties. This tells Access that the toolbar is intended to function as a shortcut (right-click) menu.
Next, add a single drop-down submenu by dragging the New Menu item from the Categories List on the Customize dialog box onto your toolbar. Inside this submenu, you can include frequently used built-in options like Cut, Copy, Paste, etc., along with your custom menu buttons that trigger your own programs—just like we did earlier with the Calendar Control.
When you change the toolbar type to Popup, Access will display a message informing you that this toolbar will now appear under the Custom group within the built-in Shortcut Menus. We’ve already seen how this works in the Animated Floating Calendar example.
Naturally, this raises the question: how do we use our custom Shortcut Menu on Forms? As we've seen earlier, when you right-click on a control in a Form, the built-in Shortcut Menu appears—where we previously inserted the Calendar display button and used it successfully.
Before we move on, let’s look at two basic approaches to presenting an application to the user. One method—which we have already explored—is to design a Control Screen (also known as a Switchboard or Dashboard). This screen acts as the central hub of the application, where all essential options like opening Data Files, processing data, and printing Reports are organized. The Control Screen remains open and accessible until the user shuts down the application.
The second method is to design a menu-driven interface, like the one we just created using Menu Bars and Toolbars, instead of a Control Screen. In this approach, the application's background remains empty, displaying only the menus at the top. This is particularly effective when you uncheck the "Display Database Window" option in the Startup settings. When a Form or Report is opened, it will occupy the otherwise blank area, providing a clean and focused user interface.
You can configure the Startup Options from the Tools menu to disable all built-in Menus and Toolbars, preventing them from appearing when the application opens. This also stops users from modifying your custom Menus or Toolbars. An example image of the Startup settings is shown below:
In the Display Form/Page control, we have selected the Startup Screen designed earlier. When the application opens, this screen briefly appears for a few seconds—signaling to the user that the application has successfully loaded and is ready for use.
Menu Bar and Shortcut Menu Bar
The Menu Bar and Shortcut Menu Bar fields in the Startup Options are set to the names of the custom menus we created. This ensures that our custom Menu Bar replaces the default built-in menu at the top of the application. Similarly, when we right-click on a text control within a form, our custom Shortcut Menu Bar will appear instead of the standard built-in shortcut menu.
There is one more important setting that applies to all three types of menus—Menu Bar, Toolbar, and Shortcut Menu—to ensure they remain consistently available. On the Form and Report property sheets, you will find four specific properties related to menu and toolbar configuration:
-
Menu Bar – Assign the name of your custom menu bar.
-
Toolbar – Assign the name of your custom toolbar.
-
Shortcut Menu Bar – Assign the name of your custom shortcut menu.
-
Shortcut Menu – Set this to Yes to enable the shortcut menu, or No to suppress it.
For example, on screens like a Control Screen, where right-click functionality isn’t needed, you can set Shortcut Menu to No to prevent the shortcut menu from appearing.
For Reports, it’s recommended to design a dedicated custom toolbar that includes print-specific built-in options such as Page Setup, Print, and Export to Word or Excel, among others. This provides users with quick access to essential report-handling functions.
Form/Report MenuBar Toolbar Properties
If your application contains many Forms and Reports, manually opening each one in Design View to update the Menu Bar/Toolbar properties and saving them can be tedious and time-consuming. A better approach is to either set these properties during the design phase of each object or write a VBA routine to apply these settings programmatically.
Instructions: Designing the Setup Form
-
Create a New Form in Design View (unbound, no table/query).
-
Add a Label control at the top and set its Caption to:
Menu Bar/Toolbar Setup
-
Add a Command Button to the form and set its Name property to:
cmdMenus
Optionally set the Caption to:Apply Menu Settings
-
Set the following Form Properties to clean up its appearance:
-
Record Selectors: No
-
Navigation Buttons: No
-
Scroll Bars: Neither
-
Dividing Lines: No
-
Auto Center: Yes
-
Border Style: Dialog (optional)
-
Pop Up: Yes (optional for a floating window)
-
Modal: Yes (optional for focus)
-
-
With the Form still open in Design View, go to View > Code or press F7 to open the Form's module.
Sample VBA Code to Paste in the Form’s Module
This code will loop through all Forms and Reports in your database and update their menu and toolbar properties.
Private Sub cmdMenus_Click() Dim msg As String, resp As Integer, X As Integer msg = "Menu Bar/Toolbar Setting " & vbCr & vbCr & "Changes on Forms/Reports" & vbCr & vbCr & "Proceed...?" resp = MsgBox(msg, vbYesNo +vbQuestion + vbDefaultButton2, "cmdMenus_click") If resp = vbYes Then X = MenuToolSet() End If End Sub Private Function MenuToolSet() Dim ctr As Container, doc As Document Dim docName As String, cdb As Database On Error GoTo MenuToolSet_Err Set cdb = CurrentDbSet ctr = cdb.Containers("Forms& quot;) ' Set MenuBar, Toolbar properties change on FormsMsgBox "Form Toolbars Setup." For Each doc In ctr.Documents docName = doc.Name If docName = "ToolbarSetup" Then ' Not on this Form GoTo nextform Else DoCmd.OpenForm docName, acDesign, , , , acHidden With Forms(docName) .MenuBar = "MyMenuBar" ' change name, if different. .Toolbar = "AgrMainToolBar" ' change name, if different. .ShortcutMenu = True .ShortcutMenuBar = "AgrShortCut" ' change if different. End With DoCmd.Close acForm, docName, acSaveYes End If nextform: Next 'MenuBar toolbar properties change on ReportsMsgbox "Menu Bar/Toolbar Setup on Reports." Set ctr = cdb.Containers("Reports") For Each doc In ctr.Documents docName = doc.Name DoCmd.OpenReport docName, acViewDesign Reports(docName) .MenuBar = "MyMenuBar" Reports(docName).Toolbar = "AgrmReport" DoCmd.Close acReport, docName, acSaveYes Next Msgbox ("Menubars/Toobars : On Forms & Reports" & vbCr & vbCr & "Setup Finished.") Set ctr = NothingSet cdb = Nothing MenuToolSet_Exit: Exit Function MenuToolSet_Err: MsgBox Err.Description Resume MenuToolSet_Exit End Function
Final Step: Save and Run the Setup Form
-
Save the Form with the name:
ToolbarSetup
-
Open the Form normally (not in design view).
-
Click the Button labeled
Apply Menu Settings
(the one namedcmdMenus
).
What Happens When You Click the Button:
-
All Forms in your database:
-
Will open in design view (in hidden mode),
-
Will have their Menu Bar, Toolbar, and Shortcut Menu properties updated automatically,
-
Will be saved and closed silently.
-
-
All Reports in your database:
-
Will also open in design view, but not hidden (because Access doesn't support hidden design mode for Reports),
-
You'll briefly see each Report flash on the screen,
-
Each will have its properties updated, saved, and then closed instantly.
-
This automated approach is far quicker and more consistent than updating each object manually, especially in larger applications.