Give an application its own ribbon
In this tutorial, you use the ribbon designer to give a small database its own ribbon: a tab with two commands, a command that appears only during development, and a File view with a task. It takes about fifteen minutes and needs only one VBA function.
Prerequisites
- Microsoft 365 Access, 32-bit or 64-bit, with the WKL Forms Object Library 1.49 or later installed and registered for the current Windows user (How to: Install the released package).
- The WKL Extensions add-in installed, so that Database Tools › Add-Ins offers WKL Ribbon Designer:
tools\install-addin.ps1in the release package (1.55 or later) installsaddin\WklExtensions.accdafor the current user. Without the add-in, you can also open the designer from the Immediate window:CreateObject("WklForms.Ribbon").ShowDesigner. - A new database in a trusted location with a form
frmCustomersand a reportrptCustomers.
Steps
1. Add a function for the export
Create a standard module with this code:
Public Function ExportCustomers() As Boolean
On Error GoTo Failed
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "tblCustomers", CurrentProject.Path & "\Customers.xlsx", True
ExportCustomers = True
Exit Function
Failed:
MsgBox "The export failed: " & Err.Description, vbExclamation
End Function
A function that a ribbon calls handles its own errors; an unhandled error would show the VBA error dialog box.
2. Open the designer
Choose Database Tools › Add-Ins › WKL Ribbon Designer. The designer opens on the Commands page.
3. Create the commands
Click New three times and fill in:
| Name | Caption | Office image | Action | Target |
|---|---|---|---|---|
cmdCustomers | Customers | FileOpen | Open form | frmCustomers |
cmdPrint | Customer List | FilePrintPreview | Open report (print preview) | rptCustomers |
cmdExport | To Excel | ExportExcel | Call VBA function | ExportCustomers |
For cmdExport, type DEV under Visible when › Profiles: the command appears only while the
database is linked with the Linked Tables Manager's DEV profile (or after
WklRibbonObject().Profile = "DEV").
4. Build the ribbon
On the Ribbons page, click Ribbon; the first ribbon is the application ribbon. Select it,
click Tab, and name the tab tabHome with the caption Home. Click Group and give it the
caption Customers. Click Entry three times and choose the three commands under Command.
Set the Size of cmdCustomers to Large. The preview on the right shows the tab.
5. Add the File view
On the File view page, click Tab (caption Modules), Task group, Category, and
Task, and choose cmdCustomers as the task's command. Under Hide, type TabPrint to hide
the built-in Access Print tab.
6. Save and reopen the database
The Check page reports ready to save. Click OK. Close the database and open it again: the Home tab shows the Customers group.
Expected result
The database has its own tab with three commands, with the export available only during development, and a File view with the task Customers. Clicking Customers opens the form, and clicking Customer List opens the report in print preview. The model is stored in USysWklRibbon and comes back in the designer the next time you open it.