How to: Show commands only in development
Show a command (or a whole group, tab, or File view tab) only in the development profile, only in the ACCDB file, or only to users the application allows.
Requires WKL Forms Object Library 1.49 or later.
Solution overview
Every command, tab, group, and File view tab in the ribbon model has a condition with three parts, all of which must hold: Profiles (the Linked Tables Manager's connection profile), the kind of file (ACCDB, ACCDE, or runtime), and Function (a public VBA function without arguments that returns True). An empty part doesn't restrict anything.
Implementation
In the ribbon designer, select the command (on the Commands page) or the group (on the Ribbons page) and fill in Visible when, for example:
| Goal | Profiles | Kind of file | Function |
|---|---|---|---|
| Developer tools | DEV | ACCDB | |
| Administrators only | IsAdmin |
||
| Never in the runtime | ACCDB, ACCDE |
The function for the condition:
Public Function IsAdmin() As Boolean
On Error Resume Next
IsAdmin = Nz(TempVars("role"), "") = "Admin"
End Function
After the sign-in sets the role, have the ribbon ask again:
TempVars("role") = "Admin"
WklRibbonObject().Invalidate
Remarks
- The profile is the one set with
WklRibbonObject().Profile; otherwise, it's the profile that most linked tables use (as withWklLinkManager.DetectEnvironment). A database without a link configuration has an empty profile, so a condition with a profile hides the element there. - The kind of database is determined once per session: the runtime counts first (an ACCDE file in the runtime counts as “runtime”), then ACCDE, and otherwise ACCDB.
- The function is called whenever Access queries the element, so keep it fast and give it its own error handling.
- Hiding is a convenience, not security: anyone who can open the database can run the action. Check permissions in the data source.