Creating custom Ribbons - part 3

We are now at the most exciting part of the ribbons programming, which is to change the controls dynamically. We can hide, disable, insert images, change names and more. This is done through the attributes gets

Let’s see the following list of gets attributes from the button control

getDescription
getEnabled
getImage
getKeytip
getLabel
getScreentip
getShowImage
getShowLabel
getSize
getSupertip
getVisible

Scenario 1 - Imagine that an application is accessed by multiple users and that each user has a different kind of access allowed. For example, John cannot have access to the form of customers, but Carlos can access it. For this situation we can set the button on the ribbon that opens the Customers form, so that it becomes visible only to Carlos. Configure this button with the attribute getVisible, calling a specific function. This function will give to the getVisible the value true or false, determining the state of the button (visible or invisible) according to the User logged.

An example of the button that opens the Customers form:

<button
id = "btCustomers"
label = "Customers"
getVisible = "fncGetVisible"
onAction = "fncOnAction"
/>

Now I Will show you a very simple example of the function fncGetVisible:

Public Sub fncGetVisible(control As IRibbonControl, ByRef visible)

Select Case control.id 
   Case "btCustomers"
      if user = "john" then
         visible = false
      elseif user ="carlos" then
         visible = true
      end if
End Select

End Sub

Note that if the User logged in is John, the visible argument assumes the value false, and if the user logged in is Carlos, the argument assumes the value true.

Assuming then that the user logged in is John; the function will give for the attribute getVisible the value false, making the button invisible

<button
id = "btCustomers"
label = "Customers"
getVisible = "false"
onAction = "fncOnAction"
/>

Scenario 2 - Suppose an application is being designed for both English and Portuguese languages, and the buttons names on the ribbon must be loaded depending on the selected language. In this scenario we will use getLabel.

An example of the button with the attribute getLabel:

<button
id = "btCustomers"
getVisible = "fncGetVisible"
getLabel = "fncGetLabel"
onAction = "fncOnAction"
/>

The function fncGetLabel :

Public Sub fncGetLabel(control As IRibbonControl, ByRef label)

Select Case control.id 
   Case "btCustomers"
      if language = "portuguese" then
         label = "Clientes"
      elseif language = "english" then
         label = "Customers"
      end if
End Select

End Sub

If the chosen language is Portuguese, the function will give the getlabel the value “Clientes”

<button
id = "btCustomers"
getVisible = "fncGetVisible"
getLabel = "Clientes"
onAction = "fncOnAction"
/>

Scenario 3 - It is very common to also upload the buttons with our own images. This will be talked about in the fourth class, where I teach more than one way of loading them, including PNG images.

When the ribbon is loaded for the first time are evaluated each of the gets used and their values are loaded, as the functions of each attribute.

How can you get the get's to be revalidated after the ribbon is loaded?

The ribbon has two methods called Invalidate and InvalidateControl. The Invalidate revalidates all the controls of a ribbon, while the method InvalidateControl revalidates the control that you specify

Now, pretend that you want, in a given event, revalidate the state of two buttons (customers and suppliers) of a loaded ribbon. You just need to enter the id attribute of the control to be revalidated.

objRibbon.invalidateControl ("btCustomers")
objRibbon.invalidateControl ("btSuppliers")
 

To access the methods Invalidate and InvalidateControl we must do some configurations. The first one is to refer to the class "Microsoft Office 1(2/4/5/6).0 Object Library" that I have taught at the second video class.

The second configuration is to put the Ribbon in the cache, by a variable. See the code below, which must be created in a global mode

Option Compare Database
Public objRibbon As IRibbonUI

Public Sub fncRibbon(ribbon As IRibbonUI)
On Error Resume Next
'----------------------------------------------
'objRibbon will be used by us to realize changes
'in the ribbon at runtime
'----------------------------------------------
Set objRibbon = ribbon
End Sub

To complete it you need to put the ribbon in the variable objRibbon, called by the function fncRibbon. This is done by the onLoad attribute of the tag customUI. See a part of the xml:

<customUI xmlns="http://schemas.microsoft.com/office/20xx/xx/customui" 
onLoad="fncRibbon">
...
...
</customUI>

See the methods available by the variable objRibbon:

Usando Access

 

Video class

In this video class you will have a brief presentation of the attributes gets. You will learn, in detail, how to set up the ribbons for the dynamic exchange of languages. You will also learn how to hide / disable the controls of the ribbon, depending on the user logged in.


 


 

Links

Subjects

Article and Video 1

 
Brief presentation of MontaRibbons
Structural concept of the XML used
How to disable all the upper ribbon of the Access
Using images from the Office’s gallery
Using internal controls of the Office
Customizing the quick toolbar
Customizing the Office Button
How to create a custom ribbon
 

Article and Video 2

 
Setting the control splitButton
Setting the control menu
Differences between the controls splitButton and menu
Exporting the ribbons for your applications
How to give functionality to the buttons on the ribbon
 


Article and Video 4

Using external images (GIF, JPEG e PNG)

Article and Video 5

 

Images (GIF, JPEG, PNG e ICO) taken from the attachment type field 
 

Article 6

FAQ

Article 7

Combobox and Dropdown, in practice


MontaRibbons

All the details about how to purchase