Vous êtes sur la page 1sur 33

c 

 
   

    c


  ! "  
 
#

$%%

$%%

& Learn how you can create a custom Office Fluent Ribbon for an Access 2007 database by using
only Office Fluent extensibility markup XML and macros. Discover how to create a command space without
writing any code and also learn about more advanced scenarios that require code. (28 printed pages)

Viki Selca, Microsoft Corporation

Clint Covington, Microsoft Corporation

December 2006

#   Microsoft Office Access 2007

Download Marketing Projects.exe.

   

2
rntroducing the New Office Fluent User rnterface in Access 2007

2
Customizing the Office Fluent Ribbon in Access

2
Scenario: Marketing Projects Database

2
Advanced Scenario: Writing Code

2
Conclusion

2
Additional Resources

2
Appendix

" 
 c'(
  ! "  
 
#

$%%
One of the most exciting new developer features that Microsoft Office Access 2007 provides is the ability to
customize the Office Fluent User rnterface (Ur) in your application. The Office Fluent Ur provides a new user
model for exposing commands, and application navigation that is more discoverable and easier for users of the
application.

You create XML to change the Ribbon, a component of the new Microsoft Office Fluent user interface (Ur).
You can create customization files in any text editor. All applications that include the Office Fluent Ribbon use
the same extensibility model. Therefore, you can reuse the same Office Fluent Ur extensibility XML with a
minimum of adjustments. For example, you can reuse the custom XML you create for Access 2007 in Microsoft
Office Excel 2007, Microsoft Office Word 2007, Microsoft Office PowerPoint 2007, or Microsoft Office
Outlook 2007.

For more information about Ur extensibility architecture and the specification of the XML markup, see
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3).

The finished Marketing Projects database that is discussed later in this article is available in the accompanying
download, Marketing Projects.exe.

r   c) 

The following tools and references can help you follow the steps in this article:

2
Ä *

rf you plan to do much Ur extensibility development, it helps to have an XML editor that provides
Microsoft rntelliSense. Some free options include Microsoft Visual Basic 2005 Express Edition or
Microsoft Visual Web Developer 2005 Express Edition. For more information, see Microsoft Express
Editions.

2

 !"&
c

Schema for validating Office Fluent Ur customizations. Download the 2007 Office System: XML
Schema Reference.

2
$%%
&      "+

Lists the rDs for built-in controls. These rDs enable you to position your tabs and groups among the
built-in Office tabs and groups, or show one of the built-in tabs, groups, or controls in your solution. Ur
extensibility exposes a set of attributes for each XML element that enables you to specify the appearance
and behavior of that element. Ur extensibility also exposes a special set of attributes²   ,
 ,   ,  #   , and   ²that enable you to work with built-in controls.
Refer to Table 13 for a brief description of the attributes that are available for Ur extensibility.

Download the 2007 Office System Lists of Control rDs.

2
$%%
& "
- 

Lists the image names and rDs for built-in controls. These rDs enable you to reuse images that are
included in the built-in Office Fluent Ribbons in Office programs. Relevant attribute:   .

Download the 2007 Office System Add-rn: rcons Gallery.

    c


  .   #


Office Fluent Ribbon extensibility customizations in Access 2007 share some options with other Office
applications, but with some important differences. Just as with the other applications in the 2007 Microsoft
Office system, you customize the Office Fluent Ribbon in Access by using XML markup. Like other
applications, you can use external files that contain XML markup or COM add-ins to integrate Office Fluent
Ribbon customizations into your application. However, unlike the other Office applications, because Access
database files are binary and cannot be opened as the new Office Open XML Formats files, you cannot
customize the Office Fluent Ribbon in Access by adding parts to the database file.

Access does provide excellent flexibility in customizing the Office Fluent Ur. For example, customization
markup can be stored in a table, embedded in a Visual Basic for Applications (VBA) procedure, stored in
another Access database, or linked to from an Excel worksheet. You can also specify a custom Ur for the
application or for specific forms and reports.

There are four steps to customize the Office Fluent Ur for your database application:

1.
Create XML markup in the text editor or XML editor of your choice.

2.
Load XML into the database.

3.
Set database, form, and report properties to show customizations.

4.
Use macros or VBA to handle simple actions, such as button clicks.

For more complex applications, you can write code for the following scenarios:

2
Loading XML from a remote location.

2
Changing Office Fluent Ur content dynamically.

2
Loading custom images from the file system or from an attachment field in the database.

  Ä   /  + 

Access provides the freedom to decide where you want to store your Office Fluent Ur XML. You have two
options:

2
Store XML in a local table. This is the easy, codeless way to go. All your XML is stored in your
database and is loaded automatically at startup.

2
Store XML in a separate resource file, database, or add-in. This method requires you to write some code
to load your XML. However, it provides you the flexibility of storing your XML wherever you want.
For example, you can create an add-in that stores XML customizations that you can share among all
applications. rt is most important for loading different XML based on the current user. For example, if
the current user is part of a database administrator role, you can load an Office Fluent Ribbon that
exposes database administrator features.

Access loads Ur extensibility markup during application startup. The customizations that you load at startup are
available throughout the application during run time. You cannot load new markup after startup. However, you
can change which customization to apply.

  Ä  
r

Access looks for Ur extensibility markup in the user system table USysRibbons. You create this table and
populate it with as many records as you want. Each record in USysRibbons contains a well-formed and valid
chunk of Ur extensibility markup that can be applied to the Office Fluent Ur. For customizations to be read
correctly, you must include the two fields listed in Table 1. Any additional fields are ignored.
r.0   
  !"
   

+ 
' +
 
r
Unique name that identifies the Ur extensibility customizations in the RibbonXML
RibbonName Text
field.
RibbonX XML that describes a set of customizations to be applied to the Office Fluent
RibbonXML Memo
Ur.
' 
By default, system tables do not show in the Navigation Pane.

r c (  1


  c'2  3

1.
Click the
 
, , and then click #

 .
2.
Click   + , and then scroll to '2  .
3.
Click '2   .
4.
Select the &c (& 1
 option.

' 
This option is not available for Access Data Projects (ADPs). For these, you must use the
  !" method discussed next.

   . & 




You can load Ur extensibility markup in the application by calling the only Office Fluent Ur-specific Access
VBA object member, the #
   !" method. The signature for this method is as follows:

VB
C#
C++
F#
JScript

Copy
a a
    a    


Where:

2
a a returns an #
  object.
2
  a represents the name of the Office Fluent Ribbon.

2
  contains the XML customization markup.

Typically, to create and make the Office Fluent Ribbon available to the application, you first add a module to
the database that has a procedure that calls the   !" method, passing in the name of the Office
Fluent Ribbon and the XML customization markup. As stated earlier, the XML markup can come from a
.
 object that was created from a table, from a source external to the database (such as an XML file that
you must parse into a & ), or from XML markup embedded directly inside the procedure. Different Office
Fluent Ribbons can be made available by using multiple calls to the   !" method, passing in
different XML markup²if the RibbonName of each Office Fluent Ribbon and the  attribute of the tabs that
make up the Office Fluent Ribbons are unique.

When the procedure is complete, you then create an AutoExec macro that calls the procedure by using the
RunCode action. That way, when the application is started, the   !" method is automatically
executed, and all the custom Office Fluent Ribbons are made available to the application.

We discuss how to implement this function and load customizations from another location in the Advanced
Scenario: Writing Code section.

,    

Hold down the SHrFT key when you open the database to open it with the default Office Fluent Ribbon in
Access instead of with your custom Office Fluent Ribbon.

* 

You can turn on verbose error reporting for the Office Fluent Ribbon by selecting an option in the #


  dialog box. This property applies to all 2007 Microsoft Office system programs that have the Office
Fluent Ribbon.

r c (
  .     c    


1.
Click the
 
, , and then click #

 .
2.
Click #2
, and then scroll to - .
3.
Select the &c (    
  check box, and then click 4.

& + 5 5. 3   &c (   

Now that you know how to load your XML into the database and view errors, you can learn to display your
customizations in the Office Fluent Ur. You can assign a Office Fluent Ribbon for the following contexts:

2
+  Customizations are controlled by the .  ' property on the database.

2
 . Customizations are controlled by the .  ' property on the form or report
object.

The .  ' property is a drop-down list whose contents correspond to the RibbonName field values that
you specified at database startup, either through the USysRibbons table or through the
#
   !" method call.

+ 2   
Database-level customizations are applied at startup, immediately after your XML is loaded and your other
startup code is completed. The database customization is displayed until you close the database; that is, you
cannot assign a different customization to your database without restarting the application. However, you can
change the Office Fluent Ribbon that you load for the database through customizations that you load for forms
and reports. You should carefully plan which customizations that you apply in which context. This The section
Scenario: Marketing Projects Database discusses this concept in detail.

r !"
   (c c
    

1.
Follow one of the previously described methods for loading Ur customization markup in the database.
2.
Close and then restart the application.
3.
Click the
 
, , and then click #

 .
4.
rn the left pane, click   + , and then, in the .  r    section, select
one of the Office Fluent Ribbons in the .  ' list.
5.
Now, restart the application. The selected Office Fluent Ribbon is displayed.

.    

Form and report customizations are displayed when the object is loaded or started, and they are rolled back
again when the object is closed or loses the focus. You can apply any customizations that you want for a form
or report.

Here are two important things to consider:

2
The customizations that you apply in the form or report are additive to what is already displayed in the
Office Fluent Ribbon. That is, unless you specifically hide tabs or set the   &

c attribute to
r , the tabs displayed by a form or report's Office Fluent Ribbon are in addition to the existing tabs.

2
The customizations that you apply in the database take precedence over form or report customizations
because they are applied first. For example, if you set the   &

c attribute to r  in the
database Office Fluent Ribbon, you cannot override this setting in the form or report Office Fluent
Ribbon.

r  
  .  
        

1.
Open the form or report in Layout view. (Design view also works.)
2.
rf the property sheet is not displayed, press 6 to display it.
3.
On the  c tab of the property sheet, select one of the Office Fluent Ribbons in the .  '
list.
4.
Save, close, and then reopen the form or report. The Office Fluent Ribbon you selected is displayed.

Access provides a hidden, empty contextual tabset called AccessFormReportExtensibility, which you can use to
display Office Fluent Ribbon content for forms and reports. You should use this tabset if you are adding tabs in
your form or report customization. There are some advantages to taking this approach:

2
Adding separate tabs for your form or report enables you to move commands into the Office Fluent
Ribbon that traditionally are found in the form. You can use icons and icon size to guide the user toward
discovering the most important commands for the form.

2
Regular Office Fluent Ribbon tabs appear passively in the background. However, the contextual tabset
takes focus when the form or report is first opened. Therefore, positioning your custom tabs in the
contextual tabset has the advantage of drawing additional attention to your customizations.
The Scenario: Marketing Projects Database section discusses this technique in detail.

  &  
#


Access supports a large array of safe macros that can be run when code is not enabled for the database (safe
mode). Using macros also makes for a lightweight application because you do not have to add a VBA project
for simple actions, such as button clicks. You can implement many scenarios in a codeless database.

rt is ideal to handle the #


 callback with a macro because this callback performs an action and does not
require you to return a value to the Office Fluent Ribbon.

Ä *

The XML in the following example shows how to define the #


 attribute for controls. The Office Fluent
Ribbon calls the 
' macro in the 
1
' macro object.

XML

Copy
   a  a  a


You create macros to handle the #


 callback in the Scenario: Marketing Projects Database section.

  7,#
8

Ribbon controls contain standard attributes that you can set in the XML markup. Table 13 in the Appendix
section contains a list of the attributes that are defined by Ur extensibility. Most attributes are set when you
write the XML. These attribute values are static and cannot be changed after they are loaded into the Office
Fluent Ribbon. The attributes of type "callback" can be set dynamically as soon as the XML is loaded into the
Office Fluent Ribbon. These attributes require you to specify the name of a VBA function that the Office Fluent
Ribbon should call, instead of specifying a static string. You can handle simple callbacks, such as #
,
with a macro. However, you must write a VBA function to handle any callback that requires you to return a
value or object to the Office Fluent Ribbon. rn Access, you must also specify a VBA callback to load custom
images. This is covered in the Advanced Scenario: Writing Code section.

An advantage of VBA callbacks is that your code can reside in an add-in. One limitation is that code must be
enabled in the database for the code to run.

  "
Because Access database files are binary and cannot be opened as the new Office Open XML Formats files, you
must follow procedures that differ from other 2007 Office system applications for storing custom images and
loading them into the Office Fluent Ribbon. Your options for loading images for your Office Fluent Ribbon in
Access are as follows:

2
.

 Use the   attribute to reuse an icon that is available in Office. This
option is available in all Office applications that implement the Office Fluent Ribbon. You can use any
icon that appears in any Office application.

2
! "

8 Use the  " attribute to specify a function that provides the image. You
can also use this method in other Office applications. rn Access, you have the option of loading images
from an attachment field in an Access database.

. 
"


This is the codeless way of supplying images for your Office Fluent Ribbon in Access. Each image that appears
on the Office Fluent Ribbon in Office applications has a unique rD that you can use to reference and display it
in your custom Office Fluent Ribbon. You can use the   attribute to specify the name of a built-in
image to use.

Ä *

The following example shows how to use the   attribute to reference a built-in image.

XML

Copy
w 

a!" a"# a# a!" a" a$a%&a $a%
 & a!" a"'(

    c & 

You can use the Office OLE Library to load images from the file system. The Office Fluent Ribbon expects you
to return images in the "3
 +  object. The  3
  method can read in BMP or PNG image files and
save them to this object.

Ä *

rn the following example, a button control is declared with the  " attribute. The Office Fluent Ribbon
calls the function - " to get the image for the button.
XML

Copy
w 
"! a  a)a  a(


7,#*

The following example shows the VBA function that is called when the Office Fluent Ribbon evaluates the
XML in the previous example.

VB
C#
C++
F#
JScript

Copy
ë  )a  a #&  #!"&a* a
a#a  a #+
 a"  #,
a  a
- a,. a." a
/
a#a 
/
ë  


   # 
c  

Access provides ideal storage for images in the new attachment field. rf you are using custom images, you
should store your images in an attachment field for the following reasons:

2
rmages are stored in the database and travel with the application.

2
Attachment control provides an easy, no-fuss method for loading images into the database.
To use this method, you must have the following objects:

2
A table to store images.

2
A form to display load, edit, and display images.

2
A function to return images to the Office Fluent Ribbon.

  r & "

You can store Office Fluent Ribbon images in any table that you want. You should use the same convention as
with XML storage, and name your table "USysRibbonrmages".

' 
By default, system tables do not appear in the Navigation Pane. Use the Loading XML from a Local Table to
show system objects.

r$      


+ r +
 
'
Contains the set of BMP, PNG, or JPG images that are used in the application. You
rmages Attachment
retrieve this set of images and search for the appropriate control by name.

rn the following example, all images are stored in a single record inside the table. rf you use this approach, you
should name your images something meaningful so that you can search the field and retrieve the image later.
The advantage of storing your images in this manner is that it greatly simplifies your code. The disadvantage is
that this method does not scale up for a solution that might require hundreds of custom images.

r&     





+ r +
 
'
The identifier for the Office Fluent Ribbon control that uses the images in the rmages
Controlrd Text
field. You use this field to retrieve the images contained in the rmages field.
Contains one or more BMP, PNG, or JPG image that is associated with the control in
rmages Attachment
Controlrd.
Description Text Optional description of this image and the context in which it is used.

Another approach is to expand the schema to include additional fields that track image name, unique rD, and
other information that you need to track for your solution. By using this approach, you have one record for
every unique image for your application. rf you have alternative forms of a single image, such as a small size,
large size, transparent background, localized version, and other forms, you can group those together in the
attachment field for that record. The advantage to this approach is that it can scale up for solutions that require
many images and for solutions where you might swap different images for a control depending on context. The
disadvantage is that there is more to track, and your code for retrieving images requires some additional logic.

    9 8( c"


You need a basic form that is based on the USysRibbonrmages table (or whatever you named your table) to
work with the images.

r 
  

1.
rn the Navigation Pane, click the USysRibbonrmages table.
2.
On the    tab, in the database window, click .
3.
Save the form with the name !&.  ".

Access automatically creates an attachment control and binds the report to the correct record source for you. No
additional design steps are necessary. Now you can click in the attachment control to load images into your
database. rn the next step, you automate this form and use the attachment control to load images.

' 
The number of records that you need to store your images depends on the approach you took with the schema in
the previous section.

You write code to load custom images into your database in the Advanced Scenario: Writing Code section.

&
   8 3 1
+ 
You have seen how to customize the Office Fluent Ribbon and add images. Now, it is time to put the new
knowledge to use, by working with the Marketing Projects database available in Access 2007. As with any
software project design, you should understand the customer scenarios and design requirements. The design
goal for this project is to provide an intuitive and natural user interface that focuses on tracking a project and its
status. The design goals for this application are as follows:

2
Focus on the most important aspects of the application by simplifying navigation between the home
screen and other forms.

2
Remove commands from the Ur that are not relevant or that can potentially destabilize the database if
they are used by a novice user.

2
Reclaim as much vertical space as possible. This includes moving commands that were previously
located in the in-form toolbar to the Office Fluent Ribbon.

' 
The finished Marketing Projects database is available in the download that accompanies this article, Marketing
Projects.exe.

&    c  8 3 1


+ 

Follow these steps to create the Marketing projects database:

1.
Start Access 2007.

2.
To select the Marketing Projects database template from the - &  ( c
 

#

 screen, click    in the left pane, click  8  1


, and then click + ( .

' 
This step assumes that you are connected to the rnternet or have previously downloaded the Marketing
Projects template from Microsoft Office Online.

& $  r & 


  .     

Follow these steps to implement custom Office Fluent Ur so that it is available when the application starts:

1.
On the Office Fluent Ribbon, click the    tab.

2.
Click r.

A new table appears.

3.
Create the table by using the steps provided in the Loading XML from a Local Table section.

4.
Name your table !&.  , and then save it.

& 3  c!"      8

Next, hide the default Office Fluent Ribbon.

1.
Add a record in your USysRibbons table by using the content shown in Table 4.

r6!  c  &



c  


   

Rib
bon
Home
Na
me

Rib XML
bon
XM
L

Copy
w   #0 ,''0a * '**a'1223'24'   (
w  ë 0  a'(
w'  (

2.
Close and then restart the application.

3.
Click the
 
, , and then click #

 .
4.
Click   +  in the left pane.

5.
rn the .  r    section, select the : .   in the .  ' list.

6.
Close and restart the application.

The   &

c attribute tells the Office Fluent Ribbon not to display the default content. Your
application should resemble Figure 1.

 &   

c  c
  .  

Now you are ready to create your own customized Office Fluent Ribbon.

& 6  '(: r

rn this step, you create a new tab and a group within that tab where you add controls.

Modify the record in your USysRibbons table so that it contains the content in Table 5.

r;  (:  


   

Rib
bon
Home
Na
me

XML
Rib
bon
XM
L

Copy
w   #0 ,''0a * '**a'1223'24'   (
w  ë 0  a(
w (
w 
  # a#5a(
w 
- a # a#- a '(
w' (
w' (
w'(
w'  (

Close and then restart the application to see the changes to the Office Fluent Ribbon. Your application should
resemble Figure 2.

 $'(:  ( c3 1


 

& ;      c: r

Now you add some controls to the new tab to guide the user through your application.

  & , 

Modify the record in your USysRibbons table so that it contains the following content.

r<  :  


   

Rib
bon
Home
Na
me

XML
Rib
bon
XM
L

Copy
w   #0 ,''0a * '**a'1223'24'   (
w  ë 0  a(
w (
w 
  # a#5a(
w 
- a # a#- a (
w 

5a# a#5a & 6a - a 5a
7a# a
 aa  - a a &a   0a 6a - a 0a a
5#

% 0a0 0* 6a" a 0a
 a% 0* ##a '(
w' (
w' (
w' (
w'(
w'  (

Close and then restart the application to see the changes to the Office Fluent Ribbon. Your application should
resemble Figure 3.

 :  ( c(:  

Looking at the details of the XML:

2
The   attribute refers to a Office Fluent Ribbon image name that is pulled from the 2007
Office system rcon Gallery.

2
The #
 attribute invokes a macro named Office Fluent Ribbon  8 3 1
:  that
creates a macro object named Office Fluent Ribbon. This object contains an action called
MarketingProjectsHome that calls the OpenForm action to open the Marketing Projects Home form.

   
 : c #
2   c
  .  

1.
rn the database window, on the    tab, click #2
, and then click 
.

2.
rn the 
window, add the following action:


': MarketingProjectsHome

#
: OpenForm

#  : Marketing Projects Home, Form, , , Edit,

3.
Right-click the .   tab, and then click &2.

4.
rn the &2# dialog box, type .  .

5.
Now that your macro is available, click the customized :  button to try it out.
6.
Add some simpler buttons to open other forms and reports that relate to your marketing projects. You
want to advertise the most important objects by using buttons. rn the next section, you create a menu
with additional, lesser-used reports.

7.
Modify the record in your USysRibbons table so that it contains the content in Table 7.

r#    c!&.    





   

Rib
bon
Home
Na
me

XML

Copy
w   #0 ,''0a * '**a'1223'24'   (
w  ë 0  a(
w (
w 
  # a#5a(
Rib w 
- a # a#- a (
bon w 

5a# a#5a & 6a - a 5a
7a# a
XM  aa  - a a &a   0a 6a - a 0a
L  a
5#

% 0a0 0* 6a" a 0a
 a% 0* ##a '(
w 

a%- a # a#a%- a  a)8a%&a

7a# a &a%- a '(
w 

- a  # a#a- a  
 a0%+a #- a7a# a
 &a- a  '(
w 

- a ##a- a # a###a- a 
 a$a%&a $a%7a # &- a ##a'(
w 

- a +a#9a #a# a#- a +a#9a #a
 a$a%&a $a%7a #
 &- a +a#9a #a'(
w 

- a  +a#9a #a# a# +a#9a #a
 a&a9a%0 a:667a# a
 &- a  +a#9a #a'(
w' (
w' (
w' (
w'(
w'  (
8.
Close and then restart the application to see the changes to the Office Fluent Ribbon.

The Office Fluent Ribbon for your application should resemble Figure 4.

 6#  

     

Now you add a menu control to display the remaining reports that relate to marketing projects.

Modify the record in your USysRibbons table so that it contains the content shown in Table 8.

r#  


   

Rib
bon
Home
Na
me

XML

Rib
bon
XM Copy
L w   #0 ,''0a * '**a'1223'24'   (
w  ë 0  a(
w (
w 
  # a#5a(
w 
- a # a#- a (
w 

5a# a#5a & 6a - a 5a
7a# a
 aa  - a a &a   0a 6a - a 0a a
5#

% 0a0 0* 6a" a 0a
 a% 0* ##a '(
w 

a%- a # a#a%- a  a)8a%&a

7a# a
 &a%- a '(
w 

- a  # a#a- a  
 a0%+a #- a7a# a &a- a  '(
w 

- a ##a- a # a###a- a 
 a$a%&a $a%7a # &- a ##a'(
w 

- a +a#9a #a# a#- a +a#9a #a
 a$a%&a $a%7a #
 &- a +a#9a #a'(
wa 
 - a &a # a#a&a 
 a$a%&a $a% a7a# a(
w 

- a  #a a

+a*aa
# a# #a a
 
+a*aa

- a 
 a$a%&a $a% &- a  #a a

+a*aa
'(
w 

- a ! # a0aa # a#- a ! # a0aa 
 a$a%&a $a% &- a ! # a0aa '(
w'a (
w 

- a  +a#9a #a# a# +a#9a #a
 a&a9a%0 a:667a# a
 &- a  +a#9a #a'(
w' (
w' (
w' (
w'(
w'  (

Close and then restart the application to see the changes to the Office Fluent Ribbon. The Office Fluent Ribbon
for your application should resemble Figure 5 and Figure 6.

 ;
  .  ( c .  

 < .   

  & , 
Now you create two additional groups for objects related to vendors and employees. Each group contains a Y 
. A split button is a combination of a button and a menu. The main button has its own definition and
action, as do the items in the menu. For example, you can open a form in the main button and list detailed
options in the menu portion.

Modify the record in your USysRibbons table so that it contains the content shown in Table 9.

r#   


   

. 
 
Home
'


XML

Copy
w   #0 ,''0a * '**a'1223'24'   (
w  ë 0  a(
w (
w 
  # a#5a(
w 
- a # a#- a (
Rib w 

5a# a#5a & 6a - a 5a
bon 7a# a
XM  aa  - a a &a   0a 6a - a 0a a
L 5#

% 0a0 0* 6a" a 0a
 a% 0* ##a '(
w 

a%- a # a#a%- a 
 a)8a%&a
7a# a &a%- a '(
w 

- a  # a#a- a  
 a0%+a #- a7a# a &a- a  '(
w 

- a ##a- a # a###a- a 
 a$a%&a $a%7a # &- a ##a'(
w 

- a +a#9a #a# a#- a +a#9a #a
 a$a%&a $a%7a #
 &- a +a#9a #a'(
wa 
 - a &a # a#a&a  a$a%&a $a%
 a7a# a(
w 

- a  #a a

+a*aa
# a# #a a
 
+a*aa

- a 
 a$a%&a $a% &- a  #a a

+a*aa
'(
w 

- a ! # a0aa # a#- a ! # a0aa 
 a$a%&a $a% &- a ! # a0aa '(
w'a (
w 

- a  +a#9a #a# a# +a#9a #a
 a&a9a%0 a:667a# a
 &- a  +a#9a #a'(
w' (
w 
$a
# a#$a
(
w# ! 

$a
# ! 7a# a(
wa 
 $a
 a&a


ë #6 a7a# a(


w 

$a
 # a#$a
 
 a&a


ë #6
 &$a
 '(
w 

$a


a!6# a#

a!6
 a$a%&a $a%
 &$a


a!6'(
w 

$a
-0a # a#-0a  a$a%&a $a%
 &$a
-0a '(
w'a (
w'# ! (
w' (
w 
/#"aa# a#/#"aa(
w# ! 

/#"aa# ! 7a# a(
wa 
 /#"aa# a#"a 
 a$a%&a $a% a7a# a(
w 

/#"aa # a#/#"aa 
 a&a


ë #6 &/#"aa '(


w 

/#"aa

a!6# a#

a!6
 a$a%&a $a% &/#"aa

a!6'(
w 

/#"aa-0a # a#-0a 
 a$a%&a $a% &/#"aa-0a '(
w'a (
w'# ! (
w' (
w' (
w' (
w'(
w'  (

Close and then restart the application to see the changes to the Office Fluent Ribbon. The Office Fluent Ribbon
for your application should resemble Figure 7 and Figure 8.

 
  .  ( c(  

 &    
& <   c
 
, 

To give this application even more a custom appearance, in this section, you customize the
 

,  commands. You put the  
. command at the top level and hide the , '(, and
&2# menu commands.

Modify the record in the USysRibbons table so that it contains the content shown in Table 10.

r%    c


 
, 


   

. 
 
Home
'


XML

Rib
bon
XM
L
Copy
w   #0 ,''0a * '**a'1223'24'   (
w  ë 0  a(
w**aa (
w 
ë#a   
&a +  aa !a*aë#a #a+  a
'(
w 
ë#aa+  a9#a* #a'(
w 
ë#aa%+  a9#a* #a'(
w# ! 
ë#a 9aa a9#a* #a'(
w'**aa (
w (
w 
  # a#5a(
w 
- a # a#- a (
w 

5a# a#5a & 6a - a 5a
7a# a
 aa  - a a &a   0a 6a - a 0a a
5#

% 0a0 0* 6a" a 0a
 a% 0* ##a '(
w 

a%- a # a#a%- a  a)8a%&a

7a# a
 &a%- a '(
w 

- a  # a#a- a  
 a0%+a #- a7a# a &a- a  '(
w 

- a ##a- a # a###a- a 
 a$a%&a $a%7a # &- a ##a'(
w 

- a +a#9a #a# a#- a +a#9a #a
 a$a%&a $a%7a #
 &- a +a#9a #a'(
wa 
 - a &a # a#a&a  a$a%&a $a%
 a7a# a(
w 

- a  #a a

+a*aa
# a# #a a
 
+a*aa

- a 
 a$a%&a $a% &- a  #a a

+a*aa
'(
w 

- a ! # a0aa # a#- a ! # a0aa 
 a$a%&a $a% &- a ! # a0aa '(
w'a (
w 

- a  +a#9a #a# a# +a#9a #a
 a&a9a%0 a:667a# a
 &- a  +a#9a #a'(
w' (
w 
$a
# a#$a
(
w# ! 

$a
# ! 7a# a(
wa 
 $a
 a&a


ë #6 a7a# a(


w 

$a
 # a#$a
 
 a&a


ë #6 &$a


 '(
w 

$a


a!6# a#

a!6
 a$a%&a $a% &$a


a!6'(
w 

$a
-0a # a#-0a  a$a%&a $a%
 &$a
-0a '(
w'a (
w'# ! (
w' (
w 
/#"aa# a#/#"aa(
w# ! 

/#"aa# ! 7a# a(
wa 
 /#"aa# a#"a  a$a%&a $a%
 a7a# a(
w 

/#"aa # a#/#"aa 
 a&a


ë #6
 &/#"aa '(
w 

/#"aa

a!6# a#

a!6
 a$a%&a $a%
 &/#"aa

a!6'(
w 

/#"aa-0a # a#-0a 
 a$a%&a $a%
 &/#"aa-0a '(
w'a (
w'# ! (
w' (
w' (
w' (
w'(
w'  (
Close and then restart the application to see the changes to the Office Fluent Ribbon. The
 

,  for your application should resemble Figure 9.

 '(
 
,   

Remember, you can reuse any internal command by using the   attribute and pointing it to the name of the
command. The  ,   attribute and the  #   attribute enable you to control the position
of your command respective to other built-in commands.

&        c7    

Now that you have customized the main Office Fluent Ribbon for your database, now you can customize the
application forms. rn this section, you create customizations for the Vendor List form. You can apply the same
procedure to all the forms in your application with which you want to associate the Office Fluent Ribbon
customizations.

Create a new record in your USysRibbons table so that it contains the content shown in Table 11.

r  (  





   

. 
 
VendorList
'


Rib
bon XML
XM
L

Copy
w   #0 ,''0a * '**a'1223'24'   (
w(
w a #8 (
w a 
8 a ë&a / a# "(
w 
"8 # a#ë(
w 
  
# a#   
(
w 

5a# a#5a aa  - a a &a  
0a 6a 
- a 0a a7a# a
 & 6a - a 5a'(
w 

a%$a
# a#a%$a
 a)8a%&a

7a# a
 &a%$a
'(
w 



ë #6# a#

ë #6
 a&a


ë #67a# a


 &

ë #6'(
w 
/  / a## a#/   / a#7a #'(
w 
ë#aa
 0a # a#a
  0a 7a
 #'(
w 

##a + $ / ## a# ##a + 9 /; #
 a a a/ #7a #
 &$a
 ##a + $ / #'(
w' (
w 
)  # 
(w' (
w 
) &a
(w' (
w 
)  
ë# a(w' (
w 
) ë
a(w' (
w' (
w' a (
w' a #8 (
w'(
w'  (

Close and then restart the application to see the changes to the Office Fluent Ribbon. The Office Fluent Ribbon
for your application should resemble Figure 10.

 %
  .  
c

The following is worth noting in the XML:

2
The w a 
8 a ë&a / a# "( element tells the Office Fluent Ribbon to
insert the content into the correct tabSet. The default name for the tabSet is the   property of the
current object. By default, if you do not specify a caption, Access uses the object name.

2
The w 
/  / a## a#/   / a#7a #'( element does
not have an #
 callback specified. This is because you are reusing a built-in command. When you
click the button, the Office Fluent Ribbon executes the default action that is defined for this command.
rf you want to reuse this command, you can specify your own action in the declaration.
The commands on the  tab fall into two categories. The     group contains commands that
apply only to this form. The remaining tab content consists of built-in groups that contain data entry and
analysis tools that are applicable in all the forms in your database.

&       # , 8. 

You use the technique that you used in the previous section to add customizations for a report.

Create a new record in your USysRibbons table so that it contains the following content.

r$# 
      


   

. 
 
Reports
'


XML

Copy
w   #0 ,''0a * '**a'1223'24'   (
Rib w(
bon w a #8 (
w a 
8 a ë&a / a# "(
XM w 
"8 # a#&a (
L w 
  
# a#  
(
w 

5a# a#5a aa  - a a &a  
0a 6a 
- a 0a a7a# a
 & 6a - a 5a'(
w 
ë#a- < 67a# a'(
w 
ë#aa
 0a 7a# a'(
w 
- #08-
*/
7a# a'(
w' (
w 
)  # 
(w' (
w 
)  
ë# a(w' (
w 
) ë
a(w' (
w' (
w' a (
w' a #8 (
w'(
w'  (
Close and then restart the application to see the changes to the Office Fluent Ribbon. rt should resemble Figure
11.

 .  

The procedure for assigning customizations to a report is identical. However, the design of the Office Fluent
Ribbon is different. The . tab contains generic commands that apply to all the reports in your application.

#2
&
 9  
Next, you learn how to implement more advanced Ur extensibility scenarios in Access that require you to write
VBA code. You must write code for the following scenarios:

2
Loading XML from a remote location

2
rmplementing a callback

2
Loading custom images

    . 


 

To load XML customizations from a location other than the USysRibbons local table, follow these steps:

1.
Create a function that knows how to read your XML data from the desired location.

2.
Create the # *
macro to call your loading function at startup.

3.
Create a module and a function to load the XML from your location.

First, you create a location for your XML.

r  
   
 

1.
Rename your USysRibbons table.

As a result, Access will no longer automatically load XML customizations from this table.

Next, create the VBA module and macro that loads the Office Fluent Ribbons at startup:

2.
Start Access and open a new or existing database.
3.
On the + r  tab, click 7 ,
.
4.
On the    tab, click #2
, and then click .
5.
On the 7 ( menu in the Visual Basic Editor, click 3  9  (.
6.
rn the 3   window, in the ' property text box, change the name of the module to
.    .
7.
rn the code window, insert the following VBA code:

VB

C#

C++

F#

JScript

Copy

   a+  a



ë  
&
+ aa
+
++  a
a 
#  a +

ë28
8 #a+a*   ;4
* 4
8 #a+a* a&80a
++&a
a 
a  a +a&a
a 
8 #a+a* a
9aë 

:0#a /ë
# 
 & a$ # a&#$ # a
9aa 
:a

 #a
a  0
/
*
a 


 #a
a 
 0
/
ë  
This code creates a .
 from any table that contains the word "Ribbons" in its name. Then it calls
the   !" method to load the Office Fluent Ribbons to make them available to the database.
And finally, it closes the recordset and the reference to the +#+  object.

" 
8

rn the following example, the   element is declared with the  attribute. The label for this group is
static. This means that it is set when the group is created:

XML

Copy
w 
 9 # a# 9 (


rn the following example, the   element is declared with the   attribute. When this group is
created, the Office Fluent Ribbon calls the   function to get the value for the label.

XML

Copy
w 
 9 a  a#)a  a#(


The following example shows the VBA function that is called when the Office Fluent Ribbon evaluates the
XML in the previous example.

VB
C#
C++
F#
JScript

Copy
ë  )a  a# #&  #!"&a*# a#
a#a  a #+
 a 9 ,
 a#
" # a# a =
/
a#a 
/
ë  

The function signatures for a callback might vary depending on the control.

   "

The following VBA examples show how to implement the  " callback function to load images from an
attachment field in the current database. This function uses the form that you created in the previous step to load
images.

rn this example, all the images for the application are stored in the same record.

VB
C#
C++
F#
JScript

Copy
   a+  a
 / # 
+*aa
!#a 
+ 0 0a 

ë  )a  a a
 !"&a* a
* *aa
80a
+ 
aë"& a  # ë&a
#" 5

a
a  0ë"& a  # a
*aa
8 a
/
*
a  a 0- a+ a

/
ë  

rn this function, the USysRibbonrmages form is opened as read-only and in hidden mode. This means that you
do not see it in the Ur. Next, the images are retrieved from the rmages control. Then the image whose name
corresponds to the imagerd that is requested by the Office Fluent Ribbon is returned.

rn this example, images for the application are stored in different records. By default, if a record contains more
than one image in the rmages field, the first image is retrieved.

VB
C#
C++
F#
JScript

Copy
ë  )a  a a
 !"&a* a
 *& aë>"& a
 ë+&a
a 1
+ 0a +&a
a 1
**& a 080a
+ 
aë"& a:
%
a, 5

a
a *& aë"& a
a ë*& a&a
a 
/
*

ëë
ë   #+?@ #+@?
*ë 080a
? a* 

a  a 0
/#a
a  a*& a& a- a+
/
*
/
ë  

 
 
The ability to customize the Office Fluent Ribbon in applications is one of the most exciting new developer
features in Access 2007. rn this article, you learned how to create a custom Office Fluent Ribbon for an Access
2007 database by using Office Fluent extensibility markup XML and macros. You also learned about more
advanced scenarios that require VBA code. The Office Fluent Ribbon provides a new user model for exposing
commands and application navigation that is more discoverable and easier for users of the application. Taking
advantage of this new Ur and its extensibility features can also help make your applications look fresh and new.
# . 

For more information, see the following resources:

2
Access Developer Portal

2
Ribbon Extensibility

2
Access Community

# 
Table 13 provides a brief overview of the attributes available in Ur extensibility.

r!"      

#   r 7 +


 

  &  Description property shown in menus with itemSize="large".
 r ,  Control's enabled state.
 +
  callback Gets the description of a control.
 * callback Gets the enabled state of a control.
 " callback Gets the image of this control.
  callback Gets the label of a control.
 3  callback Gets whether the toggle button or check box is down/selected or up/cleared.
 &  callback Gets the Enhanced ScreenTip (or "Super tooltip") of a control.
 r   callback Gets the tooltip of a control.
 7   callback Gets the visibility of a control.
 &  Unique rD that you specify to identify your controls.
  control id Built-in control rD.
= qualified id Qualified name.
 &  rn COM, refers to an image string; in VBA, is a relationship rD.
  control id Copies a built-in control's icon to a custom control.
 #   control id Position after a built-in control rD.
 #  = qualified id Position after a control with a qualified name.
 ,   control id Position before a built-in control rD.
 , = qualified id Position before a control with a qualified name.
 &  Control's label.
#
 callback Function called when user clicks this control.
  r ,  Whether this check box or toggle button is selected.
c ( r ,  Whether to show the control label.
  normal, large rmage size.
  &  Control's Enhanced ScreenTip (or "Super tooltip").
  &  Control's tooltip.
2   r ,  Control's visibility.
Community Content Add
FAQ
Still only have 1 tab
r'm a little confused at how this tutorial ends up with the tabs that only appear when the respective form/report
is open. r have followed the tutorial in a sample application that r am building for my own use and though the
records are there in the USysRibbons, r never see the other tabs.

rs there any clarification to the <contextualTabs> <tabSet idMso="TabSetFormReportExtensibility">?


History

2
9/29/2010
2
Yucua

Database window = the Access application window


BHuett: rt's a little confusing, but the article was not referring to the database container (DBC), which has been
replaced by the navigation pane. Rather it was just referring to the Access application window in which your
database was opened, and the tabs at the top. Click on the Create tab, then the Advanced button, and you will be
able to create a macro from there.
History

2
7/16/2010
2
Abigail W

Bypass custom configurations


Hold the shift key down while opening the database, this will by pass your custom ribbon.
History

2
8/22/2009
2
inforit

Reference to Database Window


rn the section "Creating a Macro to Handle the onAction event of the Office Fluent Ribbon" the instructions
say: "rn the database window, on the Create tab, click Advanced, and then click Macro." However there is no
Database Window in Access 2007. rt is replaced by the Navigation Pane. Furthermore there is no
Create|Advanced|Macro option on the Navigation Pane. At this point in the exercise we have also disabled the
default ribbon so you cannot go to the Create tab there. r found it necessary to temporaily revert to showing the
ribbon with <ribbon startFromScratch="false"> in the USysRibbons entry and creating the macro in the normal
way.
History
2
3/30/2008
2
BHuett

Vous aimerez peut-être aussi