Access VBA Macro Programming

(Joao Candeias) #1
the definition for many menus and ribbons so they can be used on different forms and reports
and also as the default ribbon when the database is opened.
When the Access file is opened and you have a USysRibbons table set up, Access reads in
the XML code for the ribbon specified and applies your custom structure. You can specify
the name of a default ribbon for the whole database by clicking the File tab, clicking Options
in the left-hand pane, and then selecting Current Database in the left-hand pane of the pop-up
window. In the Ribbon and Toolbar options, you will see a drop-down for Ribbon Name.
This will show all the ribbon names you have included in your USysRibbons table.
The custom structure can be manipulated at runtime using VBA code, and you can also
make use of the predefined structure of the ribbon.
For a first-time user, it looks frightening, but fortunately Microsoft has provided a tool to
help you and make life easy. You can also find help at the official MSDN web site at
http://msdn.microsoft.com/en-gb/office/aa905530.aspx.
This contains a very useful download file of all the control IDs in the Office ribbon, and
since there are over 1,700 of them, it is very useful for reference purposes. You can also
access a number of technical articles on this page.

Creating a Ribbon Customization


To create a custom ribbon, you must first create a system table called USysRibbons within an
open database. To do this, click Create on the Access menu bar and then click the Table
Design icon in the Tables group of the ribbon.
You need to create two fields in the new table. The first is called RibbonName and is a text
field to hold the name you give to your custom ribbon. The second field is called RibbonXML
and this needs to be set to a memo field. Your table design window should now look like
Figure 11-1.
Save the table with the name of USysRibbons. You do not need a primary key on this
table. You will not see it appear in the navigation pane on the left-hand side of the Access
window unless you enable the view of system tables. To do this, right-click the bar at the very
top of the navigation pane and select Navigation Options. In the Display Options section of
the pop-up window, check the box for Show System Objects. Click OK and your new table
will appear.
Open USysRibbons for data entry by double-clicking it. In the field RibbonName, enter a
name for your custom ribbon such as MyRibbon. In the RibbonXML field, you need to enter
the XML code for the ribbon. The following sample XML can be used to remove the ribbon
completely. The File tab will still be visible because this is part of the Backstage view, not the
ribbon. The Backstage view allows you to open and close databases, set the Access default
options, and provide information about the current database.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="true">
</ribbon>
</customUI>

130 Microsoft Access 2010 VBA Macro Programming

Free download pdf