Runtime Ribbon Changes with Adrian Bell (NeoPa)

How to Add Custom Buttons to the Access Ribbon Without XML (an Access User Group talk with Adrian Bell)

Runtime Ribbon Changes with Adrian Bell (NeoPa)

Every Microsoft Access developer has faced the challenge of dynamically updating the user interface based on application state or user permissions.

In a recent Access Pacific user group presentation, Adrian Bell demonstrated a clever approach to modifying the Access ribbon at runtime using command bars. While command bars are considered legacy technology, they offer a unique capability: the ability to add custom buttons to the Add-ins tab of the ribbon programmatically through VBA code. This presentation walks through the implementation details and practical considerations for leveraging this technique in modern Access applications.

Whether you're looking to simplify your ribbon customization code or need a lightweight way to add dynamic menu options to your Access applications, this presentation offers valuable insights into working with command bars and the Add-ins tab.

Command Bar Basics

Key Concepts

  • Command bars are a legacy Office UI element still supported in modern versions
  • Custom command bars appear automatically in the Add-ins tab
  • Can be created and modified programmatically through VBA
  • Support temporary creation that automatically cleans up on close
  • No XML manipulation required

Advantages

  • Simple programmatic interface through VBA
  • Changes take effect immediately
  • No need to reload ribbon XML
  • Temporary objects don't affect other Access sessions
  • Works well for simple menu systems

Implementation Details

Core Components

  • Command bar object for the container
  • Command bar button objects for menu items
  • OnAction property specifies button behavior
  • Can call public functions or subroutines
  • Supports parameters when using functions

Code Structure

  • Class module to encapsulate command bar management
  • Methods for create, delete, show, and hide
  • Automatic cleanup on form close
  • Support for temporary vs permanent bars
  • Error handling for missing objects

Best Practices

Command Bar Management

  • Use temporary bars when possible
  • Clean up explicitly rather than relying on automatic cleanup
  • Consider using a single entry point button
  • Handle both function and subroutine callbacks
  • Implement proper error handling

UI Design

  • Keep command bar interfaces simple
  • Use for application-level functions
  • Consider launching more complex forms/menus
  • Be consistent with button naming
  • Add appropriate icons/faces to buttons

Limitations and Considerations

Technical Constraints

  • Only appears in Add-ins tab
  • Limited positioning control
  • Basic button functionality only
  • No modern ribbon features
  • Must be careful with cleanup

Usage Guidelines

  • Best for simple menu systems
  • Consider regular ribbon XML for complex UIs
  • Test cleanup thoroughly
  • Document command bar names
  • Handle multiple instances properly

Future Developments

Potential Improvements

  • Support for multiple command bars
  • Enhanced cleanup mechanisms
  • Better button organization
  • Additional control types
  • Class-based implementation

Conclusion

While command bars may be legacy technology, they provide a valuable tool for Access developers needing simple, programmatic control over the ribbon interface. Adrian's implementation demonstrates how to leverage this capability effectively while maintaining clean code and proper resource management.

Recording

The full recording is available on YouTube:

Join Live!

Want to get even more out of these presentations? Join the live Access User Group events! The next upcoming events are listed on the AUG Event Calendar.

Attending live gives you the opportunity to:

  • Interact directly with presenters during Q&A sessions
  • Network with other Access developers
  • Share your own experiences and challenges
  • Get immediate answers to your specific questions
  • Participate in group discussions

With multiple user groups across different time zones (and languages!), you're sure to find a meeting time that works for your schedule.

Custom Ribbons Using CommandBars with Adrian Bell
How to Create Custom Ribbons Using CommandBars in Microsoft Access (an Access Europe User Group talk with Adrian Bell)
Building Ribbons in Code
A list of resources and further reading to go with my Access User Group presentation on Building Ribbon Interfaces in Code.
Office Ribbon Development Resources
Links to resources and ribbon builders for VBA developers who want to add a professional touch to their applications with custom ribbon interfaces.
Ribbon - No Longer Set
Articles about customizing the Fluent UI (aka, the Office Ribbon).

Acknowledgements

  • Base cover image generated by FLUX-schnell
  • Initial draft generated by Claude-3.5-Sonnet

All original code samples by Mike Wolfe are licensed under CC BY 4.0