The Access Wizard Newsletter
Tips, Tricks, and Traps for Access Users and Developers.

Ribbon Commands Unique To You, Part 2

Introduction

An infinite number of mathematicians walk into a bar. The first mathematician orders a beer; the second orders half a beer; the third, a quarter of a beer; the fourth, an eighth of a beer.  The bartender says "You're all idiots," and pours two beers.

This joke is a play on the mathematical concept known as the limit theorem. The limit theorem describes some event that although continuing forever, ultimatelyarrives at a known point (or limit). In the case above, the bartender realizes that an infinite number of mathematicians would ultimately order a total of two beers.

As a matter of fact, if you want to get a mathematician going, ask him/her what the value is for 1.99999… where the nines continue forever. If you give him/her enough time, you will be convinced that the value is actually two.

All this leads up to one of those marginal segues into the subject of this month’s Wizard, a continuation of Ribbon Commands Unique to You. (Luckily, it doesn’t continue forever.)

Adding the Code Call to the Ribbon

In last month’s Wizard, I showed you how to create a macro that calls a function that displays a message box. This was our infrastructure to show you how to add a custom command to the Ribbon.

If you recall, the macro we created last month was called My Macro. Our goal is to have My Macro, which calls our function, show up in the ribbon so we can click on it. One thing to note before we begin is that, unless you are building a ribbon from scratch, you can only add custom code to a customized group within a tab.

So to add this code, we right-click the Ribbon and choose Customize the Ribbon, which brings up a screen similar to the one below:



To add a macro, take the following steps:

  1. Select Macros from the “Choose Commands From” drop-down.
  2. Choose “MyMacro” on the left-hand side.
  3. Click on the “My Custom Tab” that we made in September. (If you need details on how to create a customized tab, see the September Wizard.
  4. Click Add.

At this point, if everything is working properly, the “My Macro” will jump to the right-hand side and be a member of the My Custom Tab group. Note that the name given by default is My Macro and the icon that has come along for the ride is the one associated with macros.

Making Things Pretty

We are not stuck with the words My Macro, nor do we have to live with the icon that Access provides by default. To change things, click on the rename button at the bottom of the dialog box. This allows us to both change then name as it appears in the Ribbon and to give it an icon. For our purposes, I’ll call it My Independent Study so it is consistent with the name of the code. Also, I will change the icon so that it is consistent with our mathematics theme this month and choose the Pi symbol. 

At this point, click okay. You will bounce back to the normal view and should see that the "My Custom Tab" has a new item called My Independent Study. When you click it, you will get our “Hello World” message. 

Conclusion

As you can see, making this type of customization is not as easy as selecting something that is already predefined for you. There was an extra step of creating a macro which, in turn, had to call the code.

With this technique, you can make significant changes to the existing ribbon. Make no mistake – this won’t get you all the way to your own custom ribbons, because using this technique you are still stuck with using the default ribbon with its preset tabs and groups. Getting to a custom or “Bespoke Ribbon” is a much more involved process that we’ll review in future Wizards.

Trap of the Month

Changes to the Ribbon using these techniques are available only in Access 2010 and above. Unfortunately, to get to things like this in Access 2007, you have to use the considerably more complicated XML and Code Callback functionality.

Tip of the Month: More Easy Ribbon Customizations

Not only can you add your custom Tabs, Groups, and Command Buttons to the Ribbon, but using the same interface you can add, remove, and rearrange Groups. You can also change the order of default Tabs, but not remove them. Using these fairly simple techniques can get you a lot of customization, and as long as you’re willing to live with Tabs that you may not need, these techniques may well meet your needs. 
 

Quick Links:

Custom Software Home

Access Wizard Archives

Our Services

email: jim@custom-software.biz
phone: 978-392-3462
web: http://www.custom-software.biz

© Copyright Custom Software
All Rights Reserved | Westford, MA 01886

unsubscribe from this list | update subscription preferences