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

 

 


4 comment(s)

Ribbon Hacker   5/26/2013 6:36:55 AM

thanks for this tutorial! I'm developing a PowerPoint add-in to help me produce synchronized TTS audio narration. Never before programmed PowerPoint VBA, much less its Ribbon, but I'm finding just enough help on the net to help me through the exercise. Yours is the only one I've see so far that showed how to get our hands on the IRibbon handle itself. Excellent! good to know someone out there has actually gone into Ribbon Programming as deep as I have. I always have the impression that, although MS Office is the most popular office productivity app out there, but at the same time it's also the least developed in terms of the number of software developers willing to extend it.

Anyway, thanks again, and I'm back to my PP add-in project!

Peter   6/25/2013 9:26:22 AM

I have a DB that uses a custom Login form for users permissions using global variables. How can I set the Ribbon to load after the user clicks Login button so the tabs will be visible/invisible according to user access. I have only one ribbon with multi tabs.

Avelino Sampaio   6/25/2013 9:38:07 AM

Peter,

See question number 15 of the FAQ

http://www.ribbon01.com/tutoriais/faq.asp

Download the file from this example Maestro my other site (in Portuguese but I believe that you can understand)

http://www.usandoaccess.com.br/download.asp

Jean Rony Chavannes   10/11/2016 1:19:45 PM

Bonsoir,
svp pouvez m'envoyer le fichier MontaRibons en format accdb svp


Send your comment: